handleNotFoundException method

  1. @ExceptionHandler(NotFoundException)
Future<ResponseBody<Object>> handleNotFoundException(
  1. ServerHttpRequest request,
  2. ServerHttpResponse response,
  3. WebRequest webRequest,
  4. NotFoundException exception,
)

Handles NotFoundException by returning an HTTP 404 (Not Found) response.

Response structure:

{
  "status": 404,
  "message": "Resource not found"
}
  • request: the HTTP request that caused the exception
  • response: the HTTP response to populate
  • webRequest: the current web request context
  • exception: the thrown NotFoundException

Returns a ResponseBody with a 404 status code and no content.

Implementation

@ExceptionHandler(NotFoundException)
Future<ResponseBody<Object>> handleNotFoundException(
  ServerHttpRequest request,
  ServerHttpResponse response,
  WebRequest webRequest,
  NotFoundException exception
) async => ResponseBody.notFound();