[dancer-users] Hooks throwing exceptions

David Cantrell david at cantrell.org.uk
Fri Apr 4 16:53:58 BST 2014


I have an 'on_route_exception' hook defined in my application, which does
useful things like logging what happened, but boils down to ...

  hook 'on_route_exception' => sub {
      my $exception = shift;

      status($exception->status() || HTTP_INTERNAL_SERVER_ERROR);
      halt({ error => $exception->data() });
  }

I also have a 'before' hook defined that checks things like whether the
object a user is asking for belongs to them or not, and if it doesn't
calls status() and halt() appropriately. But I would like to have
the 'before' hook just throw an exception object like the rest of my
code. However, if I do, the 'on_route_exception' hook never triggers and
the exception eventually just gets stringified which isn't very useful.

Is there some other hook I should be using instead of
'on_route_exception'?

-- 
David Cantrell | Minister for Arbitrary Justice

You can't spell "slaughter" without "laughter"


More information about the dancer-users mailing list