handleHttpException method
- @ExceptionHandler(HttpException)
- ServerHttpRequest request,
- ServerHttpResponse response,
- WebRequest webRequest,
- HttpException exception,
Handles general HttpException instances by rendering a generic error page
corresponding to the provided HTTP status code.
Purpose: Serves as a catch-all handler for HTTP errors not covered by more specific exception mappings. This ensures graceful fallback rendering for custom or unanticipated HTTP conditions.
View data:
-
status: the HttpStatus derived from the exception or defaulted to 500. -
message: error summary for display. -
requestPath: originating request URI path. -
details: optional structured diagnostic data. -
request: the HTTP request that triggered the exception. -
response: the HTTP response being prepared. -
webRequest: the web request context. -
exception: the thrown HttpException.
Returns a View generated by ErrorPageUtils.generic.
Implementation
@ExceptionHandler(HttpException)
Future<View> handleHttpException(
ServerHttpRequest request,
ServerHttpResponse response,
WebRequest webRequest,
HttpException exception
) async {
final statusCode = exception.statusCode;
final status = HttpStatus.fromCode(statusCode);
return ErrorPageUtils.generic(
status,
message: exception.message,
attributes: {
'requestPath': exception.uri?.path ?? request.getRequestURI().path,
'details': exception.details,
},
);
}