-
app/Exceptions/TooManyRequestsException.php
Open in GitHubuse Exception; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; class TooManyRequestsException extends Exception { public function render(Request $request) : RedirectResponse | JsonResponse { $payload = [ 'message' => 'Too many attempts, please wait a minute', ]; return $request->expectsJson() ? response()->json($payload, Response::HTTP_TOO_MANY_REQUESTS) : back()->notify($payload['message'], 'error'); } public static function within(Response | RedirectResponse | JsonResponse $response) : bool { return $response->getStatusCode() === Response::HTTP_TOO_MANY_REQUESTS; } }
-
app/Kernels/Exception.php
Open in GitHubuse App\Exceptions\PageExpiredException; use App\Exceptions\TooManyRequestsException; use Illuminate\Foundation\Exceptions\Handler; class Exception extends Handler { protected array $exceptions = [ PageExpiredException::class, TooManyRequestsException::class, ]; // }