Created
February 27, 2016 10:02
-
-
Save SimonGenin/e0c0480b1fa039546331 to your computer and use it in GitHub Desktop.
Add whoops php error rendering in laravel 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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