Attendize/app/Exceptions/Handler.php

79 lines
1.8 KiB
PHP
Raw Normal View History

2016-02-29 15:59:36 +00:00
<?php
namespace App\Exceptions;
2016-03-05 00:18:10 +00:00
use Exception;
2016-02-29 15:59:36 +00:00
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
2016-03-05 00:18:10 +00:00
use Request;
2016-02-29 15:59:36 +00:00
2016-03-05 00:18:10 +00:00
//use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;
2016-02-29 15:59:36 +00:00
2016-03-05 00:18:10 +00:00
class Handler extends ExceptionHandler
{
2016-02-29 15:59:36 +00:00
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
2016-03-05 00:18:10 +00:00
'Symfony\Component\HttpKernel\Exception\HttpException',
2016-02-29 15:59:36 +00:00
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
2016-03-05 00:18:10 +00:00
* @param \Exception $e
*
2016-02-29 15:59:36 +00:00
* @return void
*/
2016-03-05 00:18:10 +00:00
public function report(Exception $e)
{
2016-02-29 15:59:36 +00:00
return parent::report($e);
}
/**
* Render an exception into an HTTP response.
*
2016-03-05 00:18:10 +00:00
* @param \Illuminate\Http\Request $request
* @param \Exception $e
*
2016-02-29 15:59:36 +00:00
* @return \Illuminate\Http\Response
*/
2016-03-05 00:18:10 +00:00
public function render($request, Exception $e)
{
2016-02-29 15:59:36 +00:00
if ($this->isHttpException($e)) {
return $this->renderHttpException($e);
}
if (config('app.debug')) {
return $this->renderExceptionWithWhoops($e);
}
return parent::render($request, $e);
}
/**
* Render an exception using Whoops.
2016-03-05 00:18:10 +00:00
*
* @param \Exception $e
*
2016-02-29 15:59:36 +00:00
* @return \Illuminate\Http\Response
*/
2016-03-05 00:18:10 +00:00
protected function renderExceptionWithWhoops(Exception $e)
{
$whoops = new \Whoops\Run();
if (Request::ajax()) {
$whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
2016-02-29 15:59:36 +00:00
} else {
2016-03-05 00:18:10 +00:00
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
2016-02-29 15:59:36 +00:00
}
2016-03-05 00:18:10 +00:00
2016-02-29 15:59:36 +00:00
return new \Illuminate\Http\Response(
$whoops->handleException($e), $e->getStatusCode(), $e->getHeaders()
);
}
}