[cgiapp] Best practice for CGI errors

Michael Peters mpeters at plusthree.com
Mon Sep 22 10:16:21 EDT 2008


Mark Knoop wrote:

> If one wants to return an error to the client because they have not 
> included the correct parameters for the CGI request, should one use one 
> of the HTTP status codes and if so which one? 

Generally I don't use the HTTP status codes unless there is an error on the HTTP level. So for HTTP 
redirection, general server problem, etc. But HTTP codes are not application specific codes.

> And then is it ok/sensible 
> to include an error message in the body?

For me application specific codes should be part of the application, so it's part of the response. 
Are you returning your response as structured data (XML, JSON, etc)? If so, I'd just define a part 
of the spec that lists your application specific error codes and what they mean. If your response is 
not structured data, then just put a human readable error in the response.

-- 
Michael Peters
Plus Three, LP



More information about the cgiapp mailing list