Navigation Menu

Skip to content

Commit

Permalink
handle exceptions a little smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 11, 2014
1 parent e8408b4 commit 0c2ac72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -413,13 +413,13 @@ sub _development {
my $mode = $app->mode;
my $renderer = $app->renderer;
my $options = {
snapshot => \%snapshot,
template => "$page.$mode",
format => $stash->{format} || $renderer->default_format,
exception => $page eq 'exception' ? $e : undef,
format => $stash->{format} || $renderer->default_format,
handler => undef,
status => $page eq 'exception' ? 500 : 404
snapshot => \%snapshot,
status => $page eq 'exception' ? 500 : 404,
template => "$page.$mode"
};
$options->{exception} = $e if $page eq 'exception';
my $inline = $renderer->_bundled($mode eq 'development' ? $mode : $page);
return $self if _fallbacks($self, $options, $page, $inline);
_fallbacks($self, {%$options, format => 'html'}, $page, $inline);
Expand Down
8 changes: 4 additions & 4 deletions t/mojolicious/exception_lite_app.t
Expand Up @@ -25,8 +25,8 @@ helper dead_helper => sub { die "dead helper!\n" };
hook before_render => sub {
my ($self, $args) = @_;
return unless ($args->{template} // '') eq 'not_found';
my $format = $self->stash('snapshot')->{format};
$args->{text} = "Missing $format template." if $args->{format} eq 'txt';
my $exception = $self->stash('snapshot')->{exception};
$args->{text} = "Missing template, $exception." if $args->{format} eq 'txt';
};

# Custom exception rendering for "txt"
Expand Down Expand Up @@ -63,7 +63,7 @@ get '/trapped' => sub {
$self->render(text => $@->{foo} || 'failed');
};

get '/missing_template';
get '/missing_template' => {exception => 'whatever'};

get '/missing_template/too' => sub {
my $self = shift;
Expand Down Expand Up @@ -216,7 +216,7 @@ $t->get_ok('/missing_template.json')->status_is(404)
# Missing template with custom rendering
$t->get_ok('/missing_template.txt')->status_is(404)
->content_type_is('text/plain;charset=UTF-8')
->content_is('Missing txt template.');
->content_is('Missing template, whatever.');

# Missing template (failed rendering)
$t->get_ok('/missing_template/too')->status_is(404)
Expand Down

0 comments on commit 0c2ac72

Please sign in to comment.