79553561

Date: 2025-04-03 17:00:45
Score: 0.5
Natty:
Report link

I believe the approach provided by this answer https://stackoverflow.com/a/61422022/602506 is better than the others.

What's the approach? In your @ExceptionHandler method simply call response.sendError() to set the response status which Spring Boot's BasicErrorController uses later when putting together the response. For example:

@ExceptionHandler(EmptyResultDataAccessException.class)
public void handleEntityNotFoundException(EmptyResultDataAccessException e, HttpServletResponse response) throws IOException {
    response.sendError(HttpServletResponse.SC_NOT_FOUND);
}

Why is this better?

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • RegEx Blacklisted phrase (0.5): Why is this
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
Posted by: Shannon