开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜