handleBadRequestException method
- @ExceptionHandler(BadRequestException)
- ServerHttpRequest request,
- ServerHttpResponse response,
- WebRequest webRequest,
- BadRequestException exception,
Handles BadRequestException by returning an HTTP 400 (Bad Request) response.
Response structure:
{
"error": "<error message>",
"details": "<optional error details>",
"timestamp": "<ISO timestamp>"
}
request: the HTTP request that caused the exceptionresponse: the HTTP response to populatewebRequest: the current web request contextexception: the thrown BadRequestException
Returns a ResponseBody containing structured diagnostic information.
Implementation
@ExceptionHandler(BadRequestException)
Future<ResponseBody<Object>> handleBadRequestException(
ServerHttpRequest request,
ServerHttpResponse response,
WebRequest webRequest,
BadRequestException exception
) async {
return ResponseBody.of(HttpStatus.BAD_REQUEST, {
'error': exception.message,
'details': exception.details,
'timestamp': DateTime.now().toIso8601String(),
});
}