1
votes

On fresh Laravel 5.6 installation (APP_DEBUG=true in .env file) everything works fine except this situation:

when using abort(500, 'test exception');, it shows "Whoops, looks like something went wrong." page.

when using abort(501, 'test exception');, it shows exception trace page.

My question is: why I am getting "Whoops, looks like something went wrong." when exception code is 500 and APP_DEBUG=true in .env file?

How to show the normal exception info/trace when the error code is 500 without deleting vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/views/500.blade.php.

enter image description here

1
You were right about both being httpexceptions. Here's an actual solution with a function that overrides the renderHttpException in Exception\handler.php. (I deleted my answer.) - ourmandave
To make that linked answer work you have to add use Symfony\Component\HttpKernel\Exception\HttpException; at the top of handler.php. - ourmandave
Thanks ourmandave, post this as answer so i can accepted it for you. - Usama

1 Answers

1
votes

As ourmandave suggested, the solution was to override renderHttpException function in App\Exceptions\Handler.php as follow:

protected function renderHttpException(HttpException $e)
{
    if (config('app.debug') === true) {
        //this shows Laravel exception page
        return $this->convertExceptionToResponse($e);
    }
    //continue as normal
    return parent::renderHttpException($e);
}