From: John Napiorkowski Date: Thu, 1 May 2014 20:27:41 +0000 (-0500) Subject: fixed case where end action was called even if an http style exception was thrown X-Git-Tag: 5.90064~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e25e23a7e56014e6c36e83e1b2d55106186ffe4d fixed case where end action was called even if an http style exception was thrown --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 571b120..3ec38fc 100755 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1738,6 +1738,10 @@ sub execute { my $last = pop( @{ $c->stack } ); if ( my $error = $@ ) { + #rethow if this can be handled by middleware + if(blessed $error && ($error->can('as_psgi') || $error->can('code'))) { + $error->can('rethrow') ? $error->rethrow : croak $error; + } if ( blessed($error) and $error->isa('Catalyst::Exception::Detach') ) { $error->rethrow if $c->depth > 1; } diff --git a/t/http_exceptions.t b/t/http_exceptions.t index 460769d..5cb3117 100644 --- a/t/http_exceptions.t +++ b/t/http_exceptions.t @@ -70,15 +70,19 @@ use Plack::Test; die "I'm not dead yet"; } + sub end :Private { die "We should never hit end for HTTPExceptions" } + package MyApp; use Catalyst; + MyApp->config(abort_chain_on_error_fix=>1); + sub debug { 1 } MyApp->setup_log('fatal'); } -$INC{'MyApp/Controller/Root.pm'} = '1'; # sorry... +$INC{'MyApp/Controller/Root.pm'} = __FILE__; # sorry... MyApp->setup_log('error'); Test::More::ok(MyApp->setup); @@ -90,6 +94,7 @@ test_psgi $psgi, sub { my $res = $cb->(GET "/root/from_psgi_app"); is $res->code, 404; is $res->content, 'Not Found', 'NOT FOUND'; + unlike $res->content, qr'HTTPExceptions', 'HTTPExceptions'; }; test_psgi $psgi, sub { @@ -97,6 +102,7 @@ test_psgi $psgi, sub { my $res = $cb->(GET "/root/from_catalyst"); is $res->code, 403; is $res->content, 'Forbidden', 'Forbidden'; + unlike $res->content, qr'HTTPExceptions', 'HTTPExceptions'; }; test_psgi $psgi, sub { @@ -104,6 +110,7 @@ test_psgi $psgi, sub { my $res = $cb->(GET "/root/classic_error"); is $res->code, 500; like $res->content, qr'Ex Parrot', 'Ex Parrot'; + like $res->content, qr'HTTPExceptions', 'HTTPExceptions'; }; test_psgi $psgi, sub { @@ -111,6 +118,7 @@ test_psgi $psgi, sub { my $res = $cb->(GET "/root/just_die"); is $res->code, 500; like $res->content, qr'not dead yet', 'not dead yet'; + like $res->content, qr'HTTPExceptions', 'HTTPExceptions'; }; @@ -119,5 +127,5 @@ test_psgi $psgi, sub { # in the callbacks might never get run (thus all ran tests pass but not all # required tests run). -done_testing(10); +done_testing(14);