The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

How do I return errors in REST?

I want my REST-based service to return one of several distinct errors. Which is the better approach?

1. Return the error in the body of the response, like any other data.
2. Return the error via HTTP status codes.

Also, should the approach be different for GET and POST requests?
Raj Chaudhuri Send private email
Monday, September 18, 2006
 
 
I prefer 500 series status codes with the specifics of the failure in the response.  It makes it easier to deal with in code.

Technically, I suppose, the HTTP status codes are for the actual HTTP Request and not to be abused if the service actually returns anything.  This is to keep the HTTP traffic seperate from any underlying application communication (ie// the communication was sucessful, but the application particulars created an error) which is fine in general, but I find complicates the handling in practice.

- James.
James Birchall Send private email
Monday, September 18, 2006
 
 
I prefer in the body of response.

But if your documentation is clear, it probably won't make a huge difference.
S. Tanna
Monday, September 18, 2006
 
 
Go with the body of the response.

HTTP response codes are for a different layer.  Keep it that way as many of your users are unlikely to be know/be able to fathom doing stuff with them.
KC Send private email
Monday, September 18, 2006
 
 
It depends. Some of the 400-series of HTTP status codes are fairly descriptive and can be used in conjunction with a response body. For instance, returning a '409 Conflict' code is in REST applications an indication that you're trying to transfer an old version of a representation, and the body of the response can indicate what the current version is, or what data have changed since the version you're submitting.
Chris Winters Send private email
Monday, September 18, 2006
 
 
Thanks, everyone.

Mr. Winters, your example is very close to my initial design. I often have to return an error code and additional information. My errors are essentially the ones that are defined in HTTP: resource not found, conflict, and not authorized. I guess it makes sense to go with the error code approach.
Raj Chaudhuri Send private email
Tuesday, September 19, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz