[Dancer-users] Confused on error reporting

Alexis Sukrieh sukria at sukria.net
Mon Jul 25 14:18:00 CEST 2011


Le 07/07/2011 21:36, Stephen Fenwick-Paul a écrit :
> How do I get such messages back to the caller, be it a web page, or
> most problematically a RESTful user using JSON and still re ponded with
> a meaningful code.
> I could catch all errors, and send back a nice HTML or JSON object, but
> my response would be a 200 which seems wrong.
> At present the poor user can not tell why his requests are failing.
> thanks again for an guidance.

I suggest using Dancer::Plugin::REST for using status_ERROR, like:

     if ($missing_parameter) {
         return status_bad_request("Missing parameter $foo");

Or manually, the send_entity() method:

     if ($missing_parameter) {
         return send_entity({ error => "Missing parameter $foo"}, 400);

This how we handle this case at work with our Dancer-powered API webservice.

for details


Alexis Sukrieh                -+-                Hackers gonna hack!

“The problem with quotes on the Internet is that you can't always be
sure of their authenticity.” -- Abraham Lincoln

http://sukria.net                           http://twitter.com/sukria

More information about the Dancer-users mailing list