Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom status codes are not supported #677

Open
balazs-zsoldos opened this issue Sep 3, 2021 · 2 comments
Open

Custom status codes are not supported #677

balazs-zsoldos opened this issue Sep 3, 2021 · 2 comments

Comments

@balazs-zsoldos
Copy link

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.

@whiskeysierra
Copy link
Collaborator

Makes sense, care to supply a PR?

@balazs-zsoldos
Copy link
Author

I will try to find the time to create PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants