From: David Schmidt Date: Wed, 31 Dec 2014 11:57:12 +0000 (+0100) Subject: refactor HTTP exception check X-Git-Tag: 45.90078~2^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=80172e7dd3ee0325d38c0e9b10b379af529e5790 refactor HTTP exception check --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 892fc4e..dc401c1 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -1775,16 +1775,7 @@ sub execute { if ( my $error = $@ ) { #rethow if this can be handled by middleware - if( - !$c->config->{always_catch_http_exceptions} && - blessed $error && ( - $error->can('as_psgi') || - ( - $error->can('code') && - $error->code =~m/^[1-5][0-9][0-9]$/ - ) - ) - ) { + if ( $c->_handle_http_exception($error) ) { foreach my $err (@{$c->error}) { $c->log->error($err); } @@ -1965,11 +1956,7 @@ sub finalize_error { $c->engine->finalize_error( $c, @_ ); } else { my ($error) = @{$c->error}; - if( - !$c->config->{always_catch_http_exceptions} && - blessed $error && - ($error->can('as_psgi') || $error->can('code')) - ) { + if ( $c->_handle_http_exception($error) ) { # In the case where the error 'knows what it wants', becauses its PSGI # aware, just rethow and let middleware catch it $error->can('rethrow') ? $error->rethrow : croak $error; @@ -2111,16 +2098,7 @@ sub handle_request { $status = $c->finalize; } catch { #rethow if this can be handled by middleware - if( - !$class->config->{always_catch_http_exceptions} && - blessed($_) && ( - $_->can('as_psgi') || - ( - $_->can('code') && - $_->code =~m/^[1-5][0-9][0-9]$/ - ) - ) - ) { + if ( $class->_handle_http_exception($_) ) { $_->can('rethrow') ? $_->rethrow : croak $_; } chomp(my $error = $_); @@ -3443,6 +3421,22 @@ sub default_data_handlers { }; } +sub _handle_http_exception { + my ( $self, $error ) = @_; + if ( + !$self->config->{always_catch_http_exceptions} + && blessed $error + && ( + $error->can('as_psgi') + || ( $error->can('code') + && $error->code =~ m/^[1-5][0-9][0-9]$/ ) + ) + ) + { + return 1; + } +} + =head2 $c->stack Returns an arrayref of the internal execution stack (actions that are