Created
November 20, 2016 13:37
-
-
Save midnite81/ba4676fc34687bd13ef90a0a10edf265 to your computer and use it in GitHub Desktop.
Overwriting default action in Laravel 5.3 error handler
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
// 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