handleUnauthorizedException method
- @ExceptionHandler(UnauthorizedException)
- ServerHttpRequest request,
- ServerHttpResponse response,
- WebRequest webRequest,
- UnauthorizedException exception,
Handles UnauthorizedException by rendering an HTTP 401 (Unauthorized) error view.
Purpose: Informs users that authentication is required before accessing the requested resource. Commonly used to redirect users toward the login page.
View data:
-
message: human-readable explanation of the authentication failure. -
loginUrl: path to the login endpoint (default:/login). -
requestPath: the URI path where the error occurred. -
request: the HTTP request that triggered the exception. -
response: the HTTP response being prepared. -
webRequest: the web request context. -
exception: the thrown UnauthorizedException.
Returns a View generated by ErrorPageUtils.unauthorized.
Implementation
@ExceptionHandler(UnauthorizedException)
Future<View> handleUnauthorizedException(
ServerHttpRequest request,
ServerHttpResponse response,
WebRequest webRequest,
UnauthorizedException exception
) async => ErrorPageUtils.unauthorized(
message: exception.message,
loginUrl: '/login',
requestPath: exception.uri?.path ?? request.getRequestURI().path,
);