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.
精彩评论