problem-spring-web
problem-spring-web copied to clipboard
Custom status codes are not supported
We would like to use custom status codes like 555 that tells the client how to process and display the response body for the user.
With the current code of AdviceTraits it is not possible.
Description
There were several issues at Spring side before to support custom status codes. Since Spring 4.1 there is a status(int) function for the ResponseEntity that can be used for custom status codes.
Expected Behavior
The following code should initiate a response with status 555:
Problem.builder().withStatus(new Custom555Status.INSTANCE).build();
The implementation of Custom555Status returns the code 555.
Actual Behavior
An exception is thrown:
java.lang.IllegalArgumentException: No matching constant for [555]
at org.springframework.http.HttpStatus.valueOf(HttpStatus.java:540)
at org.zalando.problem.spring.web.advice.AdviceTrait.create(AdviceTrait.java:121)
at org.zalando.problem.spring.web.advice.AdviceTrait.create(AdviceTrait.java:110)
at org.zalando.problem.spring.web.advice.AdviceTrait.create(AdviceTrait.java:105)
Possible Fix
Use responseEntity.status(int) in the AdviceTraits class and also accept only status code for logging.
Steps to Reproduce
The sample code written above.
Makes sense, care to supply a PR?
I will try to find the time to create PR.