problem-spring-web icon indicating copy to clipboard operation
problem-spring-web copied to clipboard

Custom status codes are not supported

Open balazs-zsoldos opened this issue 3 years ago • 2 comments

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.

balazs-zsoldos avatar Sep 03 '21 12:09 balazs-zsoldos

Makes sense, care to supply a PR?

whiskeysierra avatar Sep 06 '21 13:09 whiskeysierra

I will try to find the time to create PR.

balazs-zsoldos avatar Sep 07 '21 07:09 balazs-zsoldos