|
4 | 4 |
|
5 | 5 | use GuzzleHttp\Exception\RequestException; |
6 | 6 | use Illuminate\Database\Eloquent\Model; |
| 7 | +use Illuminate\Foundation\Application; |
7 | 8 | use Illuminate\Http\UploadedFile; |
8 | 9 | use Illuminate\Notifications\Slack\BlockKit\Blocks\SectionBlock; |
9 | 10 | use Illuminate\Notifications\Slack\SlackMessage; |
@@ -61,7 +62,7 @@ public function getExceptionData(\Throwable $exception): array |
61 | 62 | $data['host'] = Request::server('SERVER_NAME'); |
62 | 63 | $data['method'] = Request::method(); |
63 | 64 | $data['fullUrl'] = Request::fullUrl(); |
64 | | - $data['exception'] = $exception->getMessage(); |
| 65 | + $data['exception'] = $exception->getMessage() ?? '-'; |
65 | 66 | $data['error'] = $exception->getTraceAsString(); |
66 | 67 | $data['line'] = $exception->getLine(); |
67 | 68 | $data['file'] = $exception->getFile(); |
@@ -176,6 +177,12 @@ private function logError($exception): void |
176 | 177 | $block->field("*File:*\n{$exception['file']}")->markdown(); |
177 | 178 | $block->field("*Line:*\n{$exception['line']}")->markdown(); |
178 | 179 | $block->field("*Date:*\n{$date}")->markdown(); |
| 180 | + }) |
| 181 | + ->sectionBlock(function (SectionBlock $block) use ($exception) { |
| 182 | + $payload = json_encode($exception['storage']['PARAMETERS'] ?? [], JSON_PRETTY_PRINT); |
| 183 | + $block->text( |
| 184 | + "*Payload*: ```{$payload}```" |
| 185 | + )->markdown(); |
179 | 186 | }); |
180 | 187 |
|
181 | 188 | $url = config('slack-logging.webhook_url'); |
@@ -211,11 +218,13 @@ private function createExceptionString(array $data): string |
211 | 218 |
|
212 | 219 | public function getUser(): ?array |
213 | 220 | { |
214 | | - /** @var \Illuminate\Contracts\Auth\Authenticatable $user */ |
215 | | - $user = auth()->user(); |
| 221 | + if (function_exists('auth') && (app() instanceof Application && auth()->check())) { |
| 222 | + /** @var \Illuminate\Contracts\Auth\Authenticatable $user */ |
| 223 | + $user = auth()->user(); |
216 | 224 |
|
217 | | - if ($user instanceof Model) { |
218 | | - return $user->toArray(); |
| 225 | + if ($user instanceof Model) { |
| 226 | + return $user->toArray(); |
| 227 | + } |
219 | 228 | } |
220 | 229 |
|
221 | 230 | return null; |
|
0 commit comments