Replies: 2 comments 1 reply
-
Found a solution, I can rebind ExceptionHandler contract to my own Handler. But the code doesn't look very elegant. $app = Application::configure(basePath: dirname(__DIR__))
// ...
->create();
$app->singleton(
\Illuminate\Contracts\Debug\ExceptionHandler::class,
\App\Exceptions\Handler::class
);
$using = function (Exceptions $exceptions) {
// ...
};
$app->afterResolving(
\App\Exceptions\Handler::class,
fn ($handler) => $using(new Exceptions($handler)),
);
return $app; |
Beta Was this translation helpful? Give feedback.
0 replies
-
Got a much better answer from laracasts return Application::configure(basePath: dirname(__DIR__))
->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (ValidationException $e, Request $request) {
if ($request->expectsJson()) {
return response()->json([
'message' => $e->getMessage(),
'error' => SystemErrorCode::FormValidateFailed->value,
'data' => $e->errors()
], 200);
}
return null;
});
})->create(); |
Beta Was this translation helpful? Give feedback.
1 reply
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.
Uh oh!
There was an error while loading. Please reload this page.
-
In the previous version, I was able to override invalidJson at App\Exceptions\Handler. However, in Laravel 11, this Handler has been removed. How can I achieve it using withExceptions in
bootstrap/app.php
?Beta Was this translation helpful? Give feedback.
All reactions