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); }