From 33d3338bcbfe6c563864f66637bdfa8ff68a33ea Mon Sep 17 00:00:00 2001 From: "J. Stebens" Date: Sun, 5 Mar 2017 20:16:24 +0100 Subject: [PATCH] Restore layout after route exception happened --- lib/Dancer2/Plugin/Ajax.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Dancer2/Plugin/Ajax.pm b/lib/Dancer2/Plugin/Ajax.pm index c6b7c62..1321b7b 100644 --- a/lib/Dancer2/Plugin/Ajax.pm +++ b/lib/Dancer2/Plugin/Ajax.pm @@ -43,8 +43,14 @@ sub ajax { # disable layout my $layout = $plugin->app->config->{'layout'}; $plugin->app->config->{'layout'} = undef; - my $response = $code->(); + my $response = eval { $code->(); }; + my $error = $@; + # Restore layout first $plugin->app->config->{'layout'} = $layout; + # Then give way to the route exception + if( $error ) { + die($error); + } return $response; };