HTTP Status Code for Larger Response 413 / 400

Viewed 1520

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)

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 ?

413 Request Entity Too Large

400 "Message: Response is large"

5 Answers

My vote is for 500 - Internal Server Error, with some detail in the body. A 4xx error code indicates to the client that they should retry the request after making some modifications. 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. 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. 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. 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. Some examples:

  • 400: will not process the request due to a client error. In the past this code was only for syntax error, but nowadays is more generic: https://www.rfc-editor.org/rfc/rfc7231#section-6.5.1
  • 403: indicates that the server understood the request but refuses to authorize it.
  • 415: the payload format is not supported
  • 422: the request format and syntax are ok, but the server will not process it. Normally a good one to raise when validation fails or some semantics are not correct. More: https://www.rfc-editor.org/rfc/rfc4918#section-11.2

You can check all RFCs you want and will not find a 4xx error for this situation. 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.

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 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 403 Forbidden should be your choice.

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.

In this case, We should be returning 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. 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.

Related