2015-03-12 01:44:39 +01:00
|
|
|
<?php namespace App\Exceptions;
|
|
|
|
|
2015-06-16 21:35:35 +02:00
|
|
|
use Redirect;
|
2015-04-13 09:54:51 +02:00
|
|
|
use Utils;
|
2015-03-12 01:44:39 +01:00
|
|
|
use Exception;
|
|
|
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
2015-06-16 21:35:35 +02:00
|
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
2015-03-12 01:44:39 +01:00
|
|
|
|
|
|
|
class Handler extends ExceptionHandler {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of the exception types that should not be reported.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $dontReport = [
|
|
|
|
'Symfony\Component\HttpKernel\Exception\HttpException'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Report or log an exception.
|
|
|
|
*
|
|
|
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
|
|
|
*
|
|
|
|
* @param \Exception $e
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function report(Exception $e)
|
|
|
|
{
|
2015-09-25 11:57:40 +02:00
|
|
|
if (Utils::isNinja()) {
|
|
|
|
Utils::logError(Utils::getErrorString($e));
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return parent::report($e);
|
|
|
|
}
|
|
|
|
}
|
2015-03-12 01:44:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Render an exception into an HTTP response.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Exception $e
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function render($request, Exception $e)
|
2015-09-25 11:57:40 +02:00
|
|
|
{
|
2015-06-16 21:35:35 +02:00
|
|
|
if ($e instanceof ModelNotFoundException) {
|
|
|
|
return Redirect::to('/');
|
2015-12-13 22:22:06 +01:00
|
|
|
} elseif ($e instanceof \Illuminate\Session\TokenMismatchException) {
|
2016-02-28 19:54:31 +01:00
|
|
|
// prevent loop since the page auto-submits
|
|
|
|
if ($request->path() != 'get_started') {
|
|
|
|
// https://gist.github.com/jrmadsen67/bd0f9ad0ef1ed6bb594e
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput($request->except('password', '_token'))
|
|
|
|
->with([
|
|
|
|
'warning' => trans('texts.token_expired')
|
|
|
|
]);
|
|
|
|
}
|
2015-06-16 21:35:35 +02:00
|
|
|
}
|
2015-10-20 19:12:34 +02:00
|
|
|
|
2015-09-29 07:23:30 +02:00
|
|
|
// In production, except for maintenance mode, we'll show a custom error screen
|
2015-09-29 20:19:18 +02:00
|
|
|
if (Utils::isNinjaProd() && !Utils::isDownForMaintenance()) {
|
2015-04-28 22:13:52 +02:00
|
|
|
$data = [
|
|
|
|
'error' => get_class($e),
|
|
|
|
'hideHeader' => true,
|
|
|
|
];
|
|
|
|
|
|
|
|
return response()->view('error', $data);
|
|
|
|
} else {
|
|
|
|
return parent::render($request, $e);
|
|
|
|
}
|
2015-03-12 01:44:39 +01:00
|
|
|
}
|
|
|
|
}
|