[Dancer-users] Error handling

Joel Roth joelz at pobox.com
Tue Apr 24 14:19:27 CEST 2012


On Tue, Apr 24, 2012 at 12:19:41PM +0100, Alex C wrote:
> I think the example in the Dancer::Errror documentation is wrong. 
> The render method will build the reponse for you, so there is no need to
> use Dancer::Response.
> 
> Try this:
> 
> get '/quux' => sub { err_not_found ( '/quux' ) };
> 
> sub err_not_found {
>     my $path = shift;
>         my $error = Dancer::Error->new(
>             code    => 404,
>             message => "No such file: $path",
>         );
>         $error->render;
> }
 
Thanks, this works. 

The man page should be updated to read as follows:

---- quote ----
# taken from send_file:

   use Dancer::Error;

   my $error = Dancer::Error->new(
	   code    => 404,
	   message => "No such file: '$path'"
   );

   $error->render;
----------------

The entry for the "render" method could also more complete,
for example as follows:

----- quote -----
render

Renders a response using Dancer::Response.

The method displays the "message" field and detailed debug
information under the environment setting "show_errors: 1".

Only the error number and the message "runtime error" 
are displayed under the environment setting "show_errors: 0".
-----------------


> On 23 April 2012 08:01, Joel Roth <joelz at pobox.com> wrote:
> > Can someone help me find an example of how to use Dancer::Error
> > and Dancer::Response.
> >
> > This code (based on man Dancer::Error) gets runtime error
> > "can't find object method set via package Dancer::Response"
> >
> > ------- code ---
> > get 'quux' => sub { err_not_found ( 'quux' ) };
> >
> > sub err_not_found {
> >    my $path = shift;
> >        my $error = Dancer::Error->new(
> >            code => 404,
> >            content => "No such file: $path",
> >        );
> >        Dancer::Response->set($error->render);
> > }
> > ----------------
> >
> > Thanks,
> >
> > Joel
-- 
Joel Roth


More information about the Dancer-users mailing list