Add some real error-handling for Serialize::View
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / View.pm
index 93be123..286fc88 100644 (file)
@@ -1,21 +1,33 @@
 package Catalyst::Action::Serialize::View;
-use strict;
-use warnings;
+use Moose;
+use namespace::autoclean;
 
-use base 'Catalyst::Action';
+extends 'Catalyst::Action';
 
 sub execute {
     my $self = shift;
     my ( $controller, $c, $view ) = @_;
-    my $stash_key = $controller->config->{'serialize'}->{'stash_key'}
-      || 'rest';
+
+    my $stash_key = (
+            $controller->{'serialize'} ?
+                $controller->{'serialize'}->{'stash_key'} :
+                $controller->{'stash_key'} 
+        ) || 'rest';
 
     if ( !$c->view($view) ) {
         $c->log->error("Could not load $view, refusing to serialize");
-        return 0;
+        return;
     }
 
-    return $c->view($view)->process($c);
+    if ($c->view($view)->process($c, $stash_key)) {
+      return 1;
+    } else {
+      # This is stupid. Please improve it.
+      my $error = join("\n", @{ $c->error }) || "Error in $view";
+      $error .= "\n";
+      $c->clear_errors;
+      die $error;
+    }
 }
 
 1;