[Dancer-users] Error handling

Alex C calyx238 at gmail.com
Tue Apr 24 13:19:41 CEST 2012


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;
}


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
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users


More information about the Dancer-users mailing list