Add some real error-handling for Serialize::View
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / View.pm
CommitLineData
9a76221e 1package Catalyst::Action::Serialize::View;
930013e6 2use Moose;
3use namespace::autoclean;
9a76221e 4
930013e6 5extends 'Catalyst::Action';
9a76221e 6
7sub execute {
8 my $self = shift;
9 my ( $controller, $c, $view ) = @_;
faf5c20b 10
11 my $stash_key = (
07682cbc 12 $controller->{'serialize'} ?
13 $controller->{'serialize'}->{'stash_key'} :
14 $controller->{'stash_key'}
faf5c20b 15 ) || 'rest';
9a76221e 16
17 if ( !$c->view($view) ) {
18 $c->log->error("Could not load $view, refusing to serialize");
efab9521 19 return;
9a76221e 20 }
21
067d48ee 22 if ($c->view($view)->process($c, $stash_key)) {
23 return 1;
24 } else {
25 # This is stupid. Please improve it.
26 my $error = join("\n", @{ $c->error }) || "Error in $view";
27 $error .= "\n";
28 $c->clear_errors;
29 die $error;
30 }
9a76221e 31}
32
331;