Skip to content

Instantly share code, notes, and snippets.

@midnite81
Created November 20, 2016 13:37
Show Gist options
  • Save midnite81/ba4676fc34687bd13ef90a0a10edf265 to your computer and use it in GitHub Desktop.
Save midnite81/ba4676fc34687bd13ef90a0a10edf265 to your computer and use it in GitHub Desktop.
Overwriting default action in Laravel 5.3 error handler
// Overwriting default action of render - Laravel 5.3
public function render($request, Exception $exception)
{
...
if (! $this->isHttpException($exception) && ! config('app.debug')) {
$exception = new \Symfony\Component\HttpKernel\Exception\HttpException(500);
}
return parent::render($request, $exception);
}
// Overwrite parent method (Laravel 5.3)
/**
* Render the given HttpException.
*
* @param \Symfony\Component\HttpKernel\Exception\HttpException $e
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function renderHttpException(HttpException $e)
{
$status = $e->getStatusCode();
if (view()->exists("errors.custom")) {
return response()->view("errors.custom", ['exception' => $e], $status, $e->getHeaders());
} else {
return $this->convertExceptionToResponse($e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment