开发者

Which HttpStatusCode should I return when a POST method to add an object fails

开发者 https://www.devze.com 2023-03-17 06:37 出处:网络
Which HttpStatusCode shou开发者_C百科ld I return when a POST method to add an object fails? It could be due to a db connectivity issue, a code bug, invalid data, or any other reason.That depends on w

Which HttpStatusCode shou开发者_C百科ld I return when a POST method to add an object fails?

It could be due to a db connectivity issue, a code bug, invalid data, or any other reason.


That depends on why it failed. If it failed because the client did something wrong (i.e. tried to POST a duplicate, or tried to POST incorrectly formatted data), then you should use 400 (there are a few special cases where you might use a specific 4xx instead). If it's a bug in your server code (an unexpected exception or an ASSERT failing), then you should use 500. For more information on HTTP status codes and their meanings read the spec.

0

精彩评论

暂无评论...
验证码 换一张
取 消