0

I want to show the page 500 internal server error Page but instead of showing report or render it just displays the typical Laravel exception view with the error message .

public function report(Exception $exception)
{
    parent::report($exception);
}

/**
 * Render an exception into an HTTP response.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Exception  $exception
 * @return \Illuminate\Http\Response
 */
public function render($request, Exception $exception)
{

  //  $exception = FlattenException::create($exception);
    $statusCode = $exception->getStatusCode($exception);
    dd($statusCode);

    if ($statusCode === 404 or $statusCode === 500) {
        return response()->view('errors.' . $statusCode, [], $statusCode);
    }
    return parent::render($request, $exception);
}
Karan
  • 1,146
  • 1
  • 10
  • 24
Islam
  • 9
  • 7
  • I think your render method may be throwing an exception. To get your status code: `$statusCode = $exception->getCode();`. The `getStatusCode()` api is available for http exceptions. – Adam Rodriguez Jun 17 '19 at 17:25

3 Answers3

1

If you're seeing the woops message on 500 errors instead of a 500 error page, it is because the app is in debug mode.

In your .env file edit the following line

APP_DEBUG=true

to be

APP_DEBUG=false
Joe
  • 4,618
  • 3
  • 28
  • 35
0

Could you check your bootstrap/app.php file to see if the exception handler is bound correctly? The default configuration would be like this.

A while back I wrote a post about implementing a custom exception handler in Larvel, it might contain some useful information for your issue.

PtrTon
  • 3,705
  • 2
  • 14
  • 24
  • the boostrap/app.php is like the default one i tride also to set in .env file APP_DEBUG=false but i have always the same problem. I have created an other project just to test if it works or not and it does but in the projecg im workingon it doses not. Is there something that can cause render function in Handler.php to not work???? – Islam Jun 18 '19 at 16:10
  • In that case there's probably something we've missed. Have you tried checking configuration files? Did you register another exception handler? Does the `render()` function get called at all? Do you throw the exception during a web request or commandline execution? Do you have any middleware registered which might interfere? There's probably a ton more things to check, but you could start with those – PtrTon Jun 18 '19 at 17:23
0

since this question is relatively new I presume you are suing Laravel version 7 or 8. this is because of your render function:

function render($request, Exception $exception) 

in the original ExceptionHandler class that your Handler class extends from that, the render function is like the below:

public function render($request, Throwable $e);

the parent class needs the second parameter to be Throwable type, but you use the Exception type in your child class.

dmaon
  • 58
  • 9