From: Andrew Rodland Date: Fri, 4 Dec 2009 02:00:37 +0000 (-0600) Subject: Change Serialize::execute to expect serializers to throw an exception X-Git-Tag: 0.81~11^2~1^2~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Action-REST.git;a=commitdiff_plain;h=68c266124de8e212143d4b94c55982f986f6945c Change Serialize::execute to expect serializers to throw an exception --- diff --git a/lib/Catalyst/Action/Serialize.pm b/lib/Catalyst/Action/Serialize.pm index d47f97c..2c23151 100644 --- a/lib/Catalyst/Action/Serialize.pm +++ b/lib/Catalyst/Action/Serialize.pm @@ -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;