[dancer-users] dancer2's send_error() from module

icovnik icovnik at gmail.com
Mon Oct 1 10:44:35 BST 2018


Hello,

I'm using Dancer2 for some small apps and now I came across some
difficulty when using Dancer2's send_error() function. This function
is meant to be used to emit HTTP error to client (of course) and to
stop processing current route at that point. It works OK if I use
send_error() in route directly or in some subroutine in current
module/package. But if I use send_error() from another module, it
doesn't stop there. The same if Other module is in the same file or
use'd from Other.pm.

So the question: how to properly use send_error() from another module
to finish the route right there on the spot?

Thanks

ico

Example code:

package Server;
use Dancer2;

get '/test' => sub {
    #send_error("err", 401); # 1: end of processing, error 401
    #myfunc();               # 2: end of processing, error 402
    Other::func();           # 3: processing continues, route returns 200 OK
    return "OK";
};

sub myfunc
{
    send_error("err", 402);
    # never hits this spot
}

1;

package Other;
use Dancer2;

sub func
{
    send_error("err", 403);
    # happily continues here
}

1;


More information about the dancer-users mailing list