danishiqbal4's avatar

Handle "500 | SERVER ERROR" in laravel 9

I want to show a custom blade page for all the 500 errors in my app. All the solutions that I found are not working anymore on Laravel 9.

public function render($request, Exception $exception) {

}

All the solutions require to add a render method to Handler class which uses Exception $exception but unfortunately, Laravel 9 now shows an error "Method 'App\Exceptions\Handler::render()' is not compatible with method 'Illuminate\Foundation\Exceptions\Handler::render()'"

0 likes
12 replies
chahal's avatar

Create a cutom file 500.blade.php in resources/views/errors folder. It will work.

danishiqbal4's avatar

I tried that already but it's not working. It shows this "500 | SERVER ERROR" when I add a HTTP500.blade.php file.

But when I add a 500.blade.php file, it shows a different error:

"This page isn’t working 127.0.0.1 is currently unable to handle this request. HTTP ERROR 500"

Tray2's avatar

This says it all

"Method 'App\Exceptions\Handler::render()' is not compatible with method 'Illuminate\Foundation\Exceptions\Handler::render()'"

You handler class needs to be compatible with the one it extends .

You really should show the code giving the error.

danishiqbal4's avatar

@Tray2 It's not my code, it's a solution that used to work till Laravel 8 but does not work anymore for Laravel 9.

What I'm trying to do is that I want to handle 500 error better by showing a custom page instead of the Laravel default "500 | SERVER ERROR" message.

Tray2's avatar

@danishiqbal4 Ah so it's a package, is it abandoned? If so why don't you fork it and make the changes needed to make it work with Laravel 9, and if it's not abandoned then you should create a issue or a PR on the package to fix the problem. It's not a good idea to supress a 500 error. Not to mention, you should never ever let the users know that you have a 500 error, it's better to just System has encountered an error and it has been reported or somesuch.

danishiqbal4's avatar

@Sinnbeck Yes, I have the exact same file and I want to show custom page for any 500 error that will show on my app. The laravel docs say that we should add custom 500.blade.php file in resources/views/error folder but it does not work.

danishiqbal4's avatar

@Tray2 No, it's not a package. I think you did not understand my question. I just want to show custom page for any 500 error that will show on my app. The laravel docs say that we should add custom 500.blade.php file in resources/views/error folder but it does not work.

Tray2's avatar

@danishiqbal4 That is a very bad practice in my opinion. If something goes wrong it should be logged, and not shown to the user, ever. A generic message that something went wrong is much better, but best is to make sure it never happens. You obviously have something wrong in your code, fix that instead of trying to display a 500 error gracefully.

Please or to participate in this conversation.