Last active
August 19, 2018 11:44
-
-
Save DCzajkowski/195c9c34fc0868d7548b4e8f017dd3b5 to your computer and use it in GitHub Desktop.
app/Exceptions/Handler.php
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
<?php | |
namespace App\Exceptions; | |
use Exception; | |
use Illuminate\Support\ViewErrorBag; | |
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; | |
class Handler extends ExceptionHandler | |
{ | |
// ... | |
/** | |
* Prepare a response for the given exception. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Exception $e | |
* @return \Symfony\Component\HttpFoundation\Response | |
*/ | |
protected function prepareResponse($request, Exception $e) | |
{ | |
if (view()->exists($view = "errors.{$e->getStatusCode()}")) { | |
return response()->view($view, [ | |
'errors' => new ViewErrorBag, | |
'exception' => $e, | |
], $e->getStatusCode(), $e->getHeaders()); | |
} | |
if (view()->exists($view = 'errors.default')) { // you can also add `&& config('app.env') !== 'local'` for this behavior to only happen in production | |
return response()->view($view, [ | |
'errors' => new ViewErrorBag, | |
'exception' => $e, | |
], $e->getStatusCode(), $e->getHeaders()); | |
} | |
return parent::prepareResponse($request, Exception $e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment