简体   繁体   English

较大响应的 HTTP 状态代码 413 / 400

[英]HTTP Status Code for Larger Response 413 / 400

I am getting below error when response is larger in size, We can fix below by enabling Streaming in Apigee ( Currently out of scope as needs work at all up streams)当响应的大小较大时,我遇到以下错误,我们可以通过在 Apigee 中启用流式处理来解决以下问题(目前超出范围,因为需要在所有上游工作)

The error pasted below: {"Envelope":{"Body":{"Fault":{"faultcode":"soap:Server","detail":{"source":{"errorcode":"protocol.http.TooBigBody"}},"faultstring":"Body buffer overflow","faultactor":{}}},"encodingStyle":"http:\/\/schemas.xmlsoap.org\/soap\/encoding\/"}

I am planning raise fault when we get above error from downstream system.当我们从下游系统得到上述错误时,我计划引发错误。 What should be HTTP Status Code ? HTTP 状态码应该是什么?

413 Request Entity Too Large 413请求实体太大

400 "Message: Response is large" 400“消息:响应很大”

My vote is for 500 - Internal Server Error , with some detail in the body.我的投票是500 - Internal Server Error ,正文中有一些细节。 A 4xx error code indicates to the client that they should retry the request after making some modifications. 4xx 错误代码向客户端指示他们应该在进行一些修改后重试请求。 That does not seem to be the case here.这里似乎并非如此。

If you will/can not do anything to return a response with expected body attributes to the clients in this case, then you should return 500 with a good message.在这种情况下,如果您将/不能做任何事情来向客户端返回具有预期正文属性的响应,那么您应该返回 500 和一条好的消息。 I saw services return 200 and the details of the issue at some part of the response with a good (okay) message as errorMessage or something in similar cases.我看到服务返回 200 以及响应的某些部分的问题的详细信息,并带有一个好的(好的)消息作为 errorMessage 或类似情况下的其他内容。 The idea here is to propagate the exception so that the client app can give a proper message to the end users, so let the client application know about the issue with the message.这里的想法是传播异常,以便客户端应用程序可以向最终用户提供正确的消息,因此让客户端应用程序知道消息的问题。

Well, it looks like it should be a 500 error.嗯,看起来应该是 500 错误。 And, as a good practice, you should add some details in the body or a good and clear message, as said before by some wise people here.而且,作为一个好的做法,你应该在正文中添加一些细节或一个好的和清晰的信息,正如一些聪明的人之前所说的那样。

All the 4xx errors indicates that the system is fine but your request is not.所有 4xx 错误都表明系统正常,但您的请求不是。 Some examples:一些例子:

  • 400 : will not process the request due to a client error. 400 : 由于客户端错误,不会处理请求。 In the past this code was only for syntax error, but nowadays is more generic: https://tools.ietf.org/html/rfc7231#section-6.5.1过去此代码仅用于语法错误,但现在更通用: https : //tools.ietf.org/html/rfc7231#section-6.5.1
  • 403 : indicates that the server understood the request but refuses to authorize it. 403 :表示服务器理解请求但拒绝授权。
  • 415 : the payload format is not supported 415 : 不支持负载格式
  • 422 : the request format and syntax are ok, but the server will not process it. 422 : 请求格式和语法没问题,但服务器不会处理。 Normally a good one to raise when validation fails or some semantics are not correct.通常在验证失败或某些语义不正确时提出一个很好的方法。 More: https://tools.ietf.org/html/rfc4918#section-11.2更多: https : //tools.ietf.org/html/rfc4918#section-11.2

You can check all RFCs you want and will not find a 4xx error for this situation.您可以检查您想要的所有 RFC,在这种情况下不会发现 4xx 错误。 Unless you misexplained and the user should change the request in any way in order to get the right result.除非您解释错误并且用户应该以任何方式更改请求以获得正确的结果。 In this case, 422 could be your choice, for example, if the request is in the right format and syntax, but the user is requesting too many resources.在这种情况下, 422可能是您的选择,例如,如果请求采用正确的格式和语法,但用户请求的资源过多。

HTTP 413 Payload Too Large is wrong status code for this situation because it tells to the clients that you are sending large request and it leads to confusion of them.对于这种情况, HTTP 413 Payload Too Large错误的状态代码,因为它告诉客户端您正在发送大请求并导致它们混淆。
HTTP 400 Bad Request is wrong status code for this situation because the request is correct and server knows what it wants to get but because of its own limits, server doesn't want to answer to this amount of response size. HTTP 400 Bad Request在这种情况下是错误的状态代码,因为请求是正确的,服务器知道它想要得到什么,但由于自身的限制,服务器不想回答这个响应大小。

HTTP 403 Forbidden should be your choice . HTTP 403 Forbidden应该是您的选择

The server understood the request, but is refusing to fulfill it.服务器理解请求,但拒绝满足它。

Note, mostly it is a good idea to tell the reason of refusing the request with correct response status code and custom message.请注意,通常最好用正确的响应状态代码和自定义消息来说明拒绝请求的原因。

If I understood your question correctly, Your API server is not able to full fill the request it got because the response for the request is too large.如果我正确理解了您的问题,您的 API 服务器无法完全填充它收到的请求,因为请求的响应太大。

In this case, We should be returning 503 - Service Unavailable .在这种情况下,我们应该返回503 - Service Unavailable This way we can indicate that our API server not able to respond to the request temporarily, It's not a complete downtime of the API server and it's not happening for all the requests at a time which we got.通过这种方式,我们可以表明我们的 API 服务器暂时无法响应请求,这不是 API 服务器的完全停机时间,并且不会在我们收到的所有请求中都发生这种情况。 This is gonna happen only when the response/payload is too large and that too for the selective requests.只有当响应/有效负载太大时才会发生这种情况,而且对于选择性请求也是如此。 Since our API server is not able to handle and respond to the request at that moment it should be.由于我们的 API 服务器当时无法处理和响应请求,因此应该是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM