You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Laravel 10, it was possible to utilise Laravel's exception handling for internal/application errors, whilst having a fallback for errors that did not meet that criteria (e.g. incorrect database credentials).
For example, in Laravel 10, the App\Exceptions\Handler@render method could be...
publicfunctionrender($request, Throwable$exception)
{
// If local environment, or an exception that should not be reported,// allow Laravel to handle rendering.if (app()->environment('local') || $this->shouldntReport($exception)) {
returnparent::render($request, $exception);
}
// Specific handling of TokenMismatchException (e.g., redirect with error message, or return JSON error if AJAX).// This CAN be handled in Laravel 11if ($exceptioninstanceof TokenMismatchException) {
return$this->handleTokenMismatch($request);
}
// Get an appropriate status code for the exception, defaulting to 500.$code = $this->getStatusCode($exception);
// Return a generic error page to the userreturnresponse()->view('errors.generic', ['code' => $code], $code);
}
In Laravel 11, this does not appear to be possible without overriding the whole exception handler due to the loss of access to knowing if an exception should be ignored or not. Something like this does not work as it would return the generic error pages for errors like unauthenticated etc.
$exceptions->render(function (Throwable$e, Request$request) use ($exceptions) {
// Not possible to check if an exception is unreportableif (app()->environment('local')) {
return;
}
// Get the status code from the exception$code = ...;
returnresponse()->view('errors.generic', ['code' => $code], $code);
});
If no rendering is specified and it's left to Laravel, then errors that do not return specific HTTP exceptions (the easiest to replicate being incorrect database credentials) will return a generic Symfony error page. These exceptions ignore the 5xx, 500 etc. custom error pages that you can configure.
Steps To Reproduce
Generate an exception that does not have HTTP error handling, such as incorrect database credentials in the .env
Load page that triggers the exception
You'll see Symfony's generic error page shown
The text was updated successfully, but these errors were encountered:
We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?
After attempting to create a replicate (and being unable to), I narrowed it down to an exception occuring within our error template under certain conditions (e.g. no database/invalid credentials). This was causing by a view composer that was applied to the top-most layout, that all other layouts extended.
When Laravel attempted to render our error pages, it would encounter an exception and result in Laravel returning a Symfony error page.
I've fixed it by removing the specific logic from the top-most layout, alternatively I could have used a simplified error layout.
Laravel Version
11.20.0
PHP Version
8.3.1
Database Driver & Version
No response
Description
In Laravel 10, it was possible to utilise Laravel's exception handling for internal/application errors, whilst having a fallback for errors that did not meet that criteria (e.g. incorrect database credentials).
For example, in Laravel 10, the
App\Exceptions\Handler@render
method could be...In Laravel 11, this does not appear to be possible without overriding the whole exception handler due to the loss of access to knowing if an exception should be ignored or not. Something like this does not work as it would return the generic error pages for errors like unauthenticated etc.
If no rendering is specified and it's left to Laravel, then errors that do not return specific HTTP exceptions (the easiest to replicate being incorrect database credentials) will return a generic Symfony error page. These exceptions ignore the
5xx
,500
etc. custom error pages that you can configure.Steps To Reproduce
.env
The text was updated successfully, but these errors were encountered: