HTTP状态424或500,用于外部依赖项错误 [英] HTTP Status 424 or 500 for error on external dependency

查看:794
本文介绍了HTTP状态424或500,用于外部依赖项错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建具有2个依赖项的服务.其中一个依赖项是内部管理的,而第二个依赖项则需要对第三方API的外部http出站调用.该序列要求更新资源,然后执行http出站调用.

I am trying to create a service that has 2 dependencies. One of the dependencies is internally managed while the 2nd requires an external http outbound call to a third party API. The sequence requires the updating the resource and then executing the http outbound call.

所以我的问题是,如果第二步失败,返回的正确的http状态代码是什么?

So my question is, on the event of a failure on the 2nd step, what is the correct http status code to return?

响应是424还是500,并带有说明所遇到错误的消息正文?

Should the response be 424 or 500 with a message body explaining the encountered error?

  • 424:方法失败-表示该方法未在其范围内的特定资源上执行,因为该方法执行的某些部分失败导致整个方法被中止.
  • 500:内部服务器错误.

推荐答案

您要询问的故障是服务本身内部发生的故障,因此5xx状态码范围是正确的选择. 503 Service Unavailable看起来非常适合您所描述的情况.

The failure you're asking about is one that has occurred within the internals of the service itself, so a 5xx status code range is the correct choice. 503 Service Unavailable looks perfect for the situation you've described.

5xx代码用于告诉客户端,即使请求很好,服务器在执行请求时也会遇到一些问题.另一方面,使用4xx代码来告诉客户端它做错了什么(谢谢,服务器还不错). HTTP 1.1规范的10.4和10.5节解释了不同的目的的4xx和5xx代码.

5xx codes are for telling the client that even though the request was fine, the server has had some kind of problem fulfilling the request. On the other hand, 4xx codes are used to tell the client it has done something wrong (and that the server is just fine, thanks). Sections 10.4 and 10.5 of the HTTP 1.1 spec explain the different purposes of 4xx and 5xx codes.

状态代码424在 WebDAV标准中定义,用于客户需要的情况更改正在执行的操作-服务器在此没有任何问题.

Status code 424 is defined in the WebDAV standard and is for a case where the client needs to change what it is doing - the server isn't experiencing any problem here.

这篇关于HTTP状态424或500,用于外部依赖项错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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