HttpStatus code 499 is not available in Spring HttpStatus class

余生颓废 提交于 2021-01-29 08:08:37

问题


I am developing a REST API using spring boot. My requirement is "User initiates the process and user cancels the running process any time ".

When he/she cancels i am throwing a error message along with the http status code.

for this scenario i have decided to use http status code 499 .

but this status code is not available in spring framework HttpStatus class?

1.Why this status code is not part of the spring class (org.springframework.http.HttpStatus) any specific reason ?

2.What is the alternate status code i can use instead of 499 ?

Status code 499 represents the client's API closed the connection before it gets any response.


回答1:


It's not available on HttpStatus because it's not assigned in the IANA registry.

You can't resolve with HttpStatus.valueOf either, but many Spring APIs provide an int statusCode method parameter variant, so you don't have to provide HttpStatus everywhere.

Now about your use case, unless I'm missing something, if the other party cancels and closes the connection, there's no point in setting the HTTP response status since you'll never be able to write and send it - does it?




回答2:


The ENUM_CONSTANTS for HttpStatus class in Spring Framework does not have 499 status code defined.

Check Documentation here

Although,you can try to create a custom status code for your controllers for your usecase as explained in the following tutorial

Create custom status code in Spring



来源:https://stackoverflow.com/questions/53689284/httpstatus-code-499-is-not-available-in-spring-httpstatus-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!