[Dancer-users] Exception in before_template_render hook does not render error_template

Alex C calyx238 at gmail.com
Sat Apr 14 07:57:09 CEST 2012


I noticed this when trying to make a database call in the
before_template_render hook (to conditionally set a token if a row
exists). To reproduce:

$ echo "my custom error message" > views/error.tt

---------
package App;
use Dancer ':syntax';

set show_errors => 0;
set error_template => 'error.tt';

hook before_template_render => sub {    die;    };

get '/' => sub {    template 'index.tt';    };

true;
---------

It can be resolved by adding a simple check inside
Dancer::Template::Abstract::apply_renderer() :

---------
@@ -73,9 +73,13 @@ sub apply_renderer {

     ($tokens, undef) = _prepare_tokens_options($tokens);

+    my $is_error_template
+        = $view eq Dancer::Config::setting('error_template') ? 1 : 0;
+
     $view = $self->view($view);

-    Dancer::Factory::Hook->execute_hooks('before_template_render', $tokens);
+    Dancer::Factory::Hook->execute_hooks('before_template_render', $tokens)
+        unless $is_error_template;
---------

Is it worth making a PR for this?

--
Alex


More information about the Dancer-users mailing list