add proper error handling for expired CSRF Token

This commit is contained in:
Gregor Vostrak
2024-05-02 17:25:57 +02:00
parent 271d804091
commit 1c8d895c1e
4 changed files with 39 additions and 1 deletions

View File

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Throwable;
class Handler extends ExceptionHandler
@@ -29,4 +31,17 @@ class Handler extends ExceptionHandler
//
});
}
public function render($request, Throwable $e): Response|RedirectResponse
{
$response = parent::render($request, $e);
if ($response->getStatusCode() === 419) {
return back()->with([
'message' => 'The page expired, please try again.',
]);
}
return $response;
}
}