From: John Napiorkowski Date: Fri, 15 Jul 2016 17:55:00 +0000 (-0500) Subject: trap http exceptions in prepare response phase X-Git-Tag: 5.90110~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=058e4074653139386299c58678cd852d10060056;hp=33b21eec9758f7416ced7908b2aa56b2573444c2 trap http exceptions in prepare response phase --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index ecaeb94..5cebc60 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -2466,9 +2466,6 @@ sub prepare { # VERY ugly and probably shouldn't rely on ->finalize actually working catch { # failed prepare is always due to an invalid request, right? - $c->response->status(400); - $c->response->content_type('text/plain'); - $c->response->body('Bad Request'); # Note we call finalize and then die here, which escapes # finalize being called in the enclosing block.. # It in fact couldn't be called, as we don't return $c.. @@ -2476,8 +2473,20 @@ sub prepare { # breaking compat for people doing crazy things (we should set # the 400 and just return the ctx here IMO, letting finalize get called # above... - $c->finalize; - die $_; + if ( $c->_handle_http_exception($_) ) { + foreach my $err (@{$c->error}) { + $c->log->error($err); + } + $c->clear_errors; + $c->log->_flush if $c->log->can('_flush'); + $_->can('rethrow') ? $_->rethrow : croak $_; + } else { + $c->response->status(400); + $c->response->content_type('text/plain'); + $c->response->body('Bad Request'); + $c->finalize; + die $_; + } }; $c->log_request; diff --git a/t/unicode-exception-bug.t b/t/unicode-exception-bug.t index cdcbd30..14031b0 100644 --- a/t/unicode-exception-bug.t +++ b/t/unicode-exception-bug.t @@ -72,3 +72,5 @@ use Catalyst::Test 'TestApp'; } done_testing; + +#TestApp->to_app;