- 
                Notifications
    You must be signed in to change notification settings 
- Fork 41.6k
Closed
Labels
type: bugA general bugA general bug
Milestone
Description
Having exception defined like this:
@ResponseStatus(HttpStatus.NO_CONTENT)
public class NoContentException extends RuntimeException {
    public NoContentException(String id) {
        super("ID " + id + " has no content.");
    }
}And the controller method as following:
    @GetMapping(path = "/{id}/content", produces = {
            "text/plain",
            "audio/wav",
            "image/tiff"
    })
    public ResponseEntity<FileSystemResource> getContent(@PathVariable Id id, @RequestHeader(value = HttpHeaders.ACCEPT, required = false) MediaType requestedMediaType) {
        throw new NoContentException(id.toString()));
    }I would expect that the response code will be no content no matter what but while executing
curl 'http://localhost:8080/rest/1/content' -i -X GET -H 'Accept: audio/wav'
I am getting 406 (Not Acceptable) because the BasicErrorController that always attaches the body no matter what the status code is:
@RequestMapping
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
	Map<String, Object> body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.ALL));
	HttpStatus status = getStatus(request);
	return new ResponseEntity<>(body, status);
}will later cause 406 as the body cannot be converted to the requested type. It seems to be a bug to me as according to the spec the no content response should never contain body.
lem21h, aleksanderlech, kiprijonas, dotjdk and weixsunlem21h and weixsun
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug