I think this behaviour is correct, because reading from here it says: "HTTP response status code 304 Not Modified is returned by the server to indicate a successful HTTP request, yet there is no need to send the data associated with the relevant resource. Essentially, it is the same as a 200 OK status code with a specific header included. There is no message body for this response code."
So I think it is okay that it does not return any body but just want to make sure :) also in the log I can see the exception has all the data I require and I do get the 304 not modified as response using postman...
My RestControllerAdvice:
@ExceptionHandler(NotModifiedProductException.class)
@ResponseStatus(value = HttpStatus.NOT_MODIFIED)
public ResponseEntity<HandlerDTO> handlerRequestException(NotModifiedProductException e) {
log.error(HANDLER_LOG, e.getClass(), e.getMessage(), ExceptionUtils.getStackTrace(e));
return new ResponseEntity<>(new HandlerDTO(e.getClass().getSimpleName(), e.getMessage()),
HttpStatus.NOT_MODIFIED);
}
Right now I do not need it to return the body, and more knowing that the standard says 304 does not return body, but in case I really needed it to return it, is there any way?
Also I found this documentation suggested by the javadoc:
https://www.rfc-editor.org/rfc/rfc7232#section-4.1 where it says: "A 304 response cannot contain a message-body; it is always terminated by the first empty line after the header fields."