Skip to content

Commit 4b07ee7

Browse files
authored
🧑‍💻 add context to error log (#3147)
1 parent f73ae81 commit 4b07ee7

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

app/Exceptions/Handler.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,20 @@ public function render($request, Throwable $exception) {
7373

7474
return $response;
7575
}
76+
77+
/**
78+
* Builds the exception's context array.
79+
*
80+
* @return array
81+
*/
82+
protected function context(): array {
83+
try {
84+
return array_merge(parent::context(), [
85+
'url' => request()?->fullUrl(),
86+
]);
87+
} catch (Throwable) {
88+
// If request() is not available (e.g. in Artisan commands), return the default context.
89+
return parent::context();
90+
}
91+
}
7692
}

0 commit comments

Comments
 (0)