Laravel 11: Can you get exceptions in middleware? #52576
Unanswered
Mr-wangwei
asked this question in
Q&A
Replies: 1 comment 2 replies
-
I don't know why you want to do this in the middleware but yes you can. public function handle(Request $request, Closure $next)
{
try {
Log::info('Incoming Request', [
'url' => $request->fullUrl(),
'method' => $request->method(),
'headers' => $request->headers->all(),
'body' => $request->all()
]);
$response = $next($request);
Log::info('Response Status', ['status' => $response->getStatusCode()]);
return $response;
} catch (Throwable $e) {
Log::error('Exception Occurred', [
'message' => $e->getMessage(),
'stack' => $e->getTraceAsString(),
]);
throw $e;
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Can you get exceptions in middleware?
How to log requests log and add exceptions?
Beta Was this translation helpful? Give feedback.
All reactions