From f24d7d3fa929acf714b52579c95f923cddaf4239 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Sun, 12 Jan 2020 23:15:29 +0100 Subject: [PATCH] Better handling of token mismatch errors --- app/Exceptions/Handler.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index b248b742e..947c6f1d2 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -41,17 +41,22 @@ class Handler extends ExceptionHandler } /** - * Render an exception into an HTTP response. - * - * @param \Illuminate\Http\Request $request - * @param \Exception $exception - * @return \Illuminate\Http\Response + * @param \Illuminate\Http\Request $request + * @param Exception $exception + * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response + * @throws Exception */ public function render($request, Exception $exception) { if ($exception instanceof \Spatie\Permission\Exceptions\UnauthorizedException) { abort(401); } + if ($exception instanceof \Illuminate\Session\TokenMismatchException) { + return redirect() + ->back() + ->withInput($request->except(['password', 'password_confirmation'])) + ->with('error', 'The form has expired due to inactivity. Please refresh the page and try again'); + } return parent::render($request, $exception); }