Change Serialize::execute to expect serializers to throw an exception
Andrew Rodland [Fri, 4 Dec 2009 02:00:37 +0000 (20:00 -0600)]
lib/Catalyst/Action/Serialize.pm

index d47f97c..2c23151 100644 (file)
@@ -34,15 +34,17 @@ sub execute {
         "Serializing with $sclass" . ( $sarg ? " [$sarg]" : '' ) ) if $c->debug;
 
     my $rc;
-    if ( defined($sarg) ) {
-        $rc = $sclass->execute( $controller, $c, $sarg );
-    } else {
-        $rc = $sclass->execute( $controller, $c );
-    }
-    if ( $rc eq 0 ) {
+    eval {
+        if ( defined($sarg) ) {
+            $rc = $sclass->execute( $controller, $c, $sarg );
+        } else {
+            $rc = $sclass->execute( $controller, $c );
+        }
+    };
+    if ($@) {
+        return $self->_serialize_bad_request( $c, $content_type, $@ );
+    } elsif (!$rc) {
         return $self->_unsupported_media_type( $c, $content_type );
-    } elsif ( $rc ne 1 ) {
-        return $self->_serialize_bad_request( $c, $content_type, $rc );
     }
 
     return 1;