my $error = join "\n", @{$c->error};
$c->stash->{response} = { status => 'ERROR', error => $error };
$output = $s->serialize( $c->stash->{response} );
- $c->error(0); # clear errors, so our response isn't clobbered
+ $c->clear_errors;
+ $c->response->status(400);
}
# Serialize the response
};
if ($@) {
my $error = "exception in serialize: $@";
- $c->error($error);
$c->stash->{response} = { status => 'ERROR', error => $error };
$output = $s->serialize( $c->stash->{response} );
+ $c->response->status(400);
}
$c->response->output( $output );
# 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;
use strict;
use warnings;
-use Test::More tests => 3;
+use Test::More tests => 5;
use FindBin;
use lib "$FindBin::Bin/../testapp/lib";
BEGIN { use_ok 'Catalyst::Test::MessageDriven', 'StompTestApp' };
+# successful request - type is minimum attributes
my $req = "---\ntype: ping\n";
my $res = request('testcontroller', $req);
ok($res, 'response to ping message');
ok($res->is_success, 'successful response');
+
+# unsuccessful empty request - no type
+$req = "--- ~\n";
+$res = request('testcontroller', $req);
+ok($res, 'response to empty message');
+ok($res->is_error, 'unsuccessful response');