Spring HttpStatus类中不提供HttpStatus代码499 [英] HttpStatus code 499 is not available in Spring HttpStatus class

查看:86
本文介绍了Spring HttpStatus类中不提供HttpStatus代码499的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Boot开发REST API.我的要求是用户启动该过程,并且用户随时取消正在运行的过程".

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

当他/她取消活动时,我会抛出一条错误消息以及http状态代码.

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

在这种情况下,我决定使用http状态码499.

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

但是在Spring框架HttpStatus类中没有此状态代码吗?

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

1.为什么此状态代码不属于spring类(org.springframework.http.HttpStatus)有任何特定原因吗?

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

2.我可以用什么代替499的备用状态代码?

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

状态代码499表示客户端的API在获得任何响应之前已关闭连接.

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

推荐答案

HttpStatus 上不可用,因为您也不能使用 HttpStatus.valueOf 进行解析,但是许多Spring API提供了 int statusCode 方法参数变体,因此您不必提供> HttpStatus 无处不在.

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.

现在关于您的用例,除非我丢失了某些内容,否则如果对方取消并关闭了连接,则设置HTTP响应状态毫无意义,因为您将永远无法编写和发送它-做到了?

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?

这篇关于Spring HttpStatus类中不提供HttpStatus代码499的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆