Skip to content

Commit d9ab219

Browse files
committed
feat(log): Add payload to notification
1 parent c3c5444 commit d9ab219

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/SlackLogging.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use GuzzleHttp\Exception\RequestException;
66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Foundation\Application;
78
use Illuminate\Http\UploadedFile;
89
use Illuminate\Notifications\Slack\BlockKit\Blocks\SectionBlock;
910
use Illuminate\Notifications\Slack\SlackMessage;
@@ -61,7 +62,7 @@ public function getExceptionData(\Throwable $exception): array
6162
$data['host'] = Request::server('SERVER_NAME');
6263
$data['method'] = Request::method();
6364
$data['fullUrl'] = Request::fullUrl();
64-
$data['exception'] = $exception->getMessage();
65+
$data['exception'] = $exception->getMessage() ?? '-';
6566
$data['error'] = $exception->getTraceAsString();
6667
$data['line'] = $exception->getLine();
6768
$data['file'] = $exception->getFile();
@@ -176,6 +177,12 @@ private function logError($exception): void
176177
$block->field("*File:*\n{$exception['file']}")->markdown();
177178
$block->field("*Line:*\n{$exception['line']}")->markdown();
178179
$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();
179186
});
180187

181188
$url = config('slack-logging.webhook_url');
@@ -211,11 +218,13 @@ private function createExceptionString(array $data): string
211218

212219
public function getUser(): ?array
213220
{
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();
216224

217-
if ($user instanceof Model) {
218-
return $user->toArray();
225+
if ($user instanceof Model) {
226+
return $user->toArray();
227+
}
219228
}
220229

221230
return null;

0 commit comments

Comments
 (0)