summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-11-17 11:45:27 +0100
committerfranck cuny <franck@lumberjaph.net>2010-11-17 11:45:27 +0100
commitea623826396c3b028756e0f883646a4e4c817e25 (patch)
tree96d9368482a860d78cb7b03f63c3a80595d304cc
parentmock call finalize (diff)
downloadnet-http-spore-ea623826396c3b028756e0f883646a4e4c817e25.tar.gz
try / catch error on middlewares
-rw-r--r--lib/Net/HTTP/Spore/Role/Request.pm10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/Net/HTTP/Spore/Role/Request.pm b/lib/Net/HTTP/Spore/Role/Request.pm
index a0d61b1..0af15f7 100644
--- a/lib/Net/HTTP/Spore/Role/Request.pm
+++ b/lib/Net/HTTP/Spore/Role/Request.pm
@@ -46,11 +46,19 @@ sub _execute_middlewares_on_response {
     my ($self, $response, @middlewares) = @_;
 
     foreach my $mw ( reverse @middlewares ) {
-        my $res = $mw->($response);
+        my ($res, $error);
+        try {
+            $res = $mw->($response);
+        }catch{
+            $error = 1;
+            $response->code(599);
+            $response->body({error => $_, body=>$response->body});
+        };
         $response = $res
           if ( defined $res
             && Scalar::Util::blessed($res)
             && $res->isa('Net::HTTP::Spore::Response') );
+        last if $error;
     }
 
     $response;