tags:

views:

876

answers:

2

Hi,

When building REST web services in .NET, what is the most "RESTful" way of mapping System.ArgumentNullException and System.ArgumentException to HTTP status codes? My first guess would be to use HTTP 400/Bad Request with an appropriate description.

What is the recommended best practice when mapping exceptions to HTTP status codes?

A: 

It depends on the context. E.g. an ArgumentNullException could stem from a violated precondition or be an internal server error.

Regards, tamberg

tamberg
+5  A: 

In general, the 4xx status codes tell the client that the request failed but may succeed if the request i smodified. The 5xx codes inform the client about problems that where the client has no influence.

So the first distinction you have to make is between 4xx and 5xx codes, i.e. tell the client if it should retry or not.

HTTP 400 "Bad Request" should be used if the request was indeed syntactically malformed, incomplete, contradicting or otherwise basically wrong. Additionaly it may be a valid default status in the 4xx range, if no other status seems appropriate and you believe the client needs only to modify the request to succeed.

mkoeller
From the perspective of the SERVER addressing the CLIENT: * 4xx: Something was wrong on *your* side, please rephrase your question and try again * 5xx: Something went wrong on *our* side, sorry, if you can just repeat what you just said..?
conny