I want to return a 204 no content
http status code. Though I want to add a custom error messages that gives details why where was no content.
Problem: I'm using spring-mvc
, and when returning HttpStatus.NO_CONTENT
type, the response body is always removed and empty for the client!
@RestControllerAdvice
public class ExeptionHandler {
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.NO_CONTENT)
public Object handler(HttpServletRequest req, Exception e) {
return new ResponseEntity<String>(e.getMessage(), HttpStatus.NO_CONTENT);
}
}
If I change the type eg to HttpStatus.NOT_FOUND
then the error message is shown as response body.
How can I achieve the same with 204?