Skip to content

@RequestMapping produces condition should not impact error responses [SPR-16318] #20865

Closed
@spring-projects-issues

Description

@spring-projects-issues

Ammar Husain opened SPR-16318 and commented

For a vanilla REST endpoint created in Spring Boot (1.5.9 Release) as below

@RequestMapping(value = "/foo", method = RequestMethod.GET, produces = "text/csv")
public String getCsv() {
    throw new IllegalArgumentException();
}

if request has header Accept: application/json,text/csv it should respond with the JSON representation of error / HTTP 500, instead it gives HTTP 406 - Not Acceptable.

Thus Spring seems not to respect the Accept header as it has following exception in DEBUG logs -> org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

Even after adding additional message converters (StringMessageConverter) the error persists.

Moreover configuring the @RestControllerAdvice has no effect.


Affects: 4.3.13

Reference URL: https://stackoverflow.com/questions/47831530/406-when-exception-thrown-in-spring-controller-with-accept-header-of-text-csv

Issue Links:

Referenced from: commits 395792b

0 votes, 7 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions