What's the most appropriate HTTP error code for a corrupted payload (checksum failure)?

7.3k views Asked by At

I'm writing a RESTful API with some endpoints to which clients can PUT or POST chunked files (using flow.js), including a payload digest among the metadata. The server also calculates digest and will throw an error if the digests don't match, in which case the client should attempt to retry the same request with no change (at least until some retry limit is reached).

None of the standard codes seem to fit well by definition. What is the best code to use? Is there any that fits somewhat by convention?

Note: for the purposes of integration with this library, the response must not be 404, 415, 500, or 501 as they will cancel the larger operation rather than retry this portion.

I also cannot use 409 because that is being used to identify attempts to upload multiple copies of the same file, which I believe is a better use of 409 anyway.

3

There are 3 answers

0
HonoredMule On BEST ANSWER

I cannot accept Matthew's answer because it's still suggesting one of the values I'm excluded from using - and I also believe 5xx errors aren't very appropriate where the error is in the client or the transport layer.

While still looking for better options, I'll for now propose (and use) a non-standard 4xx error, especifically

419 Checksum failed

That particular value is being chosen for its proximity to codes handling errors of a similar nature and similarity to 409 which is perhaps the closest relation.

An anser will be chosen after a couple days, to provide opportunity for community concensus on a best practice approach.

3
Matthew Verstraete On

I am not aware of a standard or specific error number for a case like this but normally I would use 415 or 500. Since you are restricted from using those options I would go with a 501. Technically a 501 is a "not implemented" but it is used in cases where there server does not recognize the request OR the server lacks the ability to fulfill the request. You could argue that a checksum error makes it impossible for the server to fulfill the request.

If you want to see a list of all the options check out this wiki page and you might find something you like better

1
Steven Koch On

I think more appropriate status code when same data from user going wrong, like corrupted data is:

400 Bad Request

For me corrupted data, means like syntax error caused by the transmission of data, semantically correct but syntactically erroneous.

422 Unprocessable Entity maybe apply too. https://www.rfc-editor.org/rfc/rfc4918#section-11.2