Skip to content

Commit

Permalink
Use Symfony as a last resort exception handler
Browse files Browse the repository at this point in the history
This prevents white screens if something goes wrong with Whoops setup.
  • Loading branch information
thecrypticace committed Jun 4, 2017
1 parent 1b9d74d commit f2cd3c3
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,19 @@ protected function convertExceptionToResponse(Exception $e)
$headers = $this->isHttpException($e) ? $e->getHeaders() : [];
$statusCode = $this->isHttpException($e) ? $e->getStatusCode() : 500;

if (config('app.debug')) {
return SymfonyResponse::create(
$this->renderExceptionWithWhoops($e), $statusCode, $headers
);
} else {
return SymfonyResponse::create(
$this->renderExceptionWithSymfony($e), $statusCode, $headers
);
$showStackTraces = config('app.debug');

try {
$content = $showStackTraces
? $this->renderExceptionWithWhoops($e)
: $this->renderExceptionWithSymfony($e, $showStackTraces);
} finally {
$content = $content ?? $this->renderExceptionWithSymfony($e, $showStackTraces);
}

return SymfonyResponse::create(
$content, $statusCode, $headers
);
}

/**
Expand All @@ -282,11 +286,11 @@ protected function renderExceptionWithWhoops(Exception $e)
* @param \Exception $e
* @return string
*/
protected function renderExceptionWithSymfony(Exception $e)
protected function renderExceptionWithSymfony(Exception $e, $showStackTraces)
{
$e = FlattenException::create($e);

return (new SymfonyExceptionHandler(false))->getHtml($e);
return (new SymfonyExceptionHandler($showStackTraces))->getHtml($e);
}

/**
Expand Down

0 comments on commit f2cd3c3

Please sign in to comment.