Skip to content

Instantly share code, notes, and snippets.

@SimonGenin
Created February 27, 2016 10:02
Show Gist options
  • Save SimonGenin/e0c0480b1fa039546331 to your computer and use it in GitHub Desktop.
Save SimonGenin/e0c0480b1fa039546331 to your computer and use it in GitHub Desktop.
Add whoops php error rendering in laravel 5
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($this->isHttpException($e))
{
return $this->renderHttpException($e);
}
if (config('app.debug'))
{
return $this->renderExceptionWithWhoops($e);
}
return parent::render($request, $e);
}
/**
* Render an exception using Whoops.
*
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
protected function renderExceptionWithWhoops(Exception $e)
{
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
return new \Illuminate\Http\Response(
$whoops->handleException($e),
$e->getStatusCode(),
$e->getHeaders()
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment