Don't log TokenMismatchException errors

This commit is contained in:
Hillel Coren 2017-03-20 22:16:13 +02:00
parent ea464aa814
commit a8880be395

View File

@ -10,6 +10,7 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Foundation\Validation\ValidationException; use Illuminate\Foundation\Validation\ValidationException;
use Illuminate\Http\Exception\HttpResponseException; use Illuminate\Http\Exception\HttpResponseException;
use Illuminate\Support\Facades\Response; use Illuminate\Support\Facades\Response;
use Illuminate\Session\TokenMismatchException;
use Redirect; use Redirect;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@ -26,10 +27,11 @@ class Handler extends ExceptionHandler
* @var array * @var array
*/ */
protected $dontReport = [ protected $dontReport = [
AuthorizationException::class, TokenMismatchException::class,
HttpException::class, //AuthorizationException::class,
ModelNotFoundException::class, //HttpException::class,
ValidationException::class, //ModelNotFoundException::class,
//ValidationException::class,
]; ];
/** /**
@ -43,6 +45,10 @@ class Handler extends ExceptionHandler
*/ */
public function report(Exception $e) public function report(Exception $e)
{ {
if (! $this->shouldReport($e)) {
return false;
}
// don't show these errors in the logs // don't show these errors in the logs
if ($e instanceof NotFoundHttpException) { if ($e instanceof NotFoundHttpException) {
if (Crawler::isCrawler()) { if (Crawler::isCrawler()) {
@ -74,9 +80,10 @@ class Handler extends ExceptionHandler
if ($e instanceof ModelNotFoundException) { if ($e instanceof ModelNotFoundException) {
return Redirect::to('/'); return Redirect::to('/');
} }
if ($e instanceof \Illuminate\Session\TokenMismatchException) {
if ($e instanceof TokenMismatchException) {
// prevent loop since the page auto-submits // prevent loop since the page auto-submits
if ($request->path() != 'get_started') { if ($request->path() != 'get_started' && $request->path() != 'save_sidebar_state') {
// https://gist.github.com/jrmadsen67/bd0f9ad0ef1ed6bb594e // https://gist.github.com/jrmadsen67/bd0f9ad0ef1ed6bb594e
return redirect() return redirect()
->back() ->back()