X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FController%2FMessageDriven.pm;h=1969bfd212edc5b2345f460eafacf247b6990d5b;hb=0e4b5a7d470856adf7d8ee70fcb185ed5bff012e;hp=9e8d0d399d2199c49aa68f1fca9b513056318dac;hpb=a5ae1e8c02bf454ebeb9d0d727409fef77d904d7;p=catagits%2FCatalyst-Engine-STOMP.git diff --git a/lib/Catalyst/Controller/MessageDriven.pm b/lib/Catalyst/Controller/MessageDriven.pm index 9e8d0d3..1969bfd 100644 --- a/lib/Catalyst/Controller/MessageDriven.pm +++ b/lib/Catalyst/Controller/MessageDriven.pm @@ -60,27 +60,33 @@ sub end : Private { # Engine will send our reply based on the value of this header. $c->response->headers->header( 'X-Reply-Address' => $c->stash->{request}->{reply_to} ); + + # The wire response + my $output; + + # Load a serializer + my $serializer = $self->config->{serializer}; + my $s = Data::Serializer->new( serializer => $serializer ); # Custom error handler - steal errors from catalyst and dump them into # the stash, to get them serialized out as the reply. if (scalar @{$c->error}) { my $error = join "\n", @{$c->error}; $c->stash->{response} = { status => 'ERROR', error => $error }; - $c->error(0); # clear errors, so our response isn't clobbered + $output = $s->serialize( $c->stash->{response} ); + $c->clear_errors; + $c->response->status(400); } # Serialize the response - my $output; - my $serializer = $self->config->{serializer}; - my $s = Data::Serializer->new( serializer => $serializer ); eval { $output = $s->raw_serialize( $c->stash->{response} ); }; if ($@) { my $error = "exception in serialize: $@"; - $c->error($error); $c->stash->{response} = { status => 'ERROR', error => $error }; - $output = Dump( $c->stash->{response} ); + $output = $s->serialize( $c->stash->{response} ); + $c->response->status(400); } $c->response->output( $output ); @@ -92,7 +98,12 @@ sub default : Private { # Forward the request to the appropriate action, based on the # message type. my $action = $c->stash->{request}->{type}; - $c->forward($action, [$c->stash->{request}]); + if (defined $action) { + $c->forward($action, [$c->stash->{request}]); + } + else { + $c->error('no message type specified'); + } } __PACKAGE__->meta->make_immutable;