Skip to content

Instantly share code, notes, and snippets.

@jozefcipa
Last active December 1, 2017 19:42
Show Gist options
  • Save jozefcipa/26ce978a6aa4c5842735d5f3417c4f38 to your computer and use it in GitHub Desktop.
Save jozefcipa/26ce978a6aa4c5842735d5f3417c4f38 to your computer and use it in GitHub Desktop.
// 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('john.doe@example.com')->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