Better handling of token mismatch errors

This commit is contained in:
DariusIII
2020-01-12 23:15:29 +01:00
parent d70300d8fa
commit f24d7d3fa9
+10 -5
View File
@@ -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);
}