Last active
December 1, 2017 19:42
-
-
Save jozefcipa/26ce978a6aa4c5842735d5f3417c4f38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// app/Exceptions/Handler.php | |
public function report(Exception $exception) | |
{ | |
// log errors only in production mode and it's not http exception | |
if (env('APP_ENV') == 'production' && !$this->isHttpException($exception)) { | |
// parse html from response | |
$exceptionHtml = $this->render(null, $exception)->getContent(); | |
Mail::to('[email protected]')->send(new \App\Mail\ExceptionOccured($exceptionHtml)); | |
} | |
parent::report($exception); | |
} | |
/** | |
* Render an exception into an HTTP response. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Exception $exception | |
* @return \Illuminate\Http\Response | |
*/ | |
public function render($request, Exception $exception) | |
{ | |
if($this->isHttpException($exception)) | |
{ | |
return $this->renderHttpException($exception); | |
} | |
// Check exception rendering - if env is production, we don't want to show exception, so we send errors/500.blade.php view | |
else if (env('APP_ENV') == 'production' && $request != null) { | |
if ($exception instanceof \ErrorException) { | |
return response('Fatal Error!', 500); | |
} else { | |
return response()->view('errors.500', [], 500); | |
} | |
} | |
else | |
{ | |
return parent::render($request, $exception); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment