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"
On Fri, 4 Apr 2014 16:53:58 +0100 David Cantrell <david@cantrell.org.uk> wrote:
[...] 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'?
I think on_handler_exception *should* do the job; I believe it's a level higher than on_route_exception. Failing that, before_error_init should fire when an error is being handled, with a Dancer::Error object being passed to it. Available hooks are documented at: https://metacpan.org/pod/Dancer#hook If all else fails, a feature request for an on_hook_exception handler could make sense :) -- David Precious ("bigpresh") <davidp@preshweb.co.uk> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github
On Wed, Apr 09, 2014 at 10:49:55AM +0100, David Precious wrote:
If all else fails, a feature request for an on_hook_exception handler could make sense :)
https://github.com/PerlDancer/Dancer/issues/1014 Now, if someone can point me at where to start, I expect I can patch it myself. -- David Cantrell | A machine for turning tea into grumpiness The voices said it's a good day to clean my weapons
participants (2)
-
David Cantrell -
David Precious