[cgiapp] Best practice for CGI errors

Mark Knoop mark at rawcane.net
Mon Sep 22 11:14:27 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
>

Thanks Michael.

I was going to have a single line of text in the response containing the 
method return value which was why I was wondering if there was another way 
of indicating an error (in which case I would use the response body for an 
error message).

Of course it would be easy to include more info in the response - but then 
perhaps I should reconsider my approach re how to implement an RPC.... 
so....

...while I am here (and acknowledging that this is slightly off topic but at 
the same time it is probably somehting that many of you have had much 
experience in 'real-world' scenarios) can I ask whether CGI::App users have 
any favourite ways to do it re 'web services' ie remote methods/apis that do 
something then return some data? SOAP, XML-RPC, bespoke XML/JSON/other in 
response to GET/POST with CGI params, any other approach? My methods and 
responses are very simple. It would be nice to have hassle free security 
already there - this was the one advantage to SOAP - the main disadvantage 
being a lack of understanding on my part...

Cheers
Mark




More information about the cgiapp mailing list