This is an automated email from the git hooks/post-receive script. js pushed a commit to annotated tag v0.08 in repository libdancer-plugin-rest-perl.
commit a77a1b74d9775aae98724484ce57e6949262b6d0 Author: Yanick Champoux <yan...@babyl.dyndns.org> Date: Mon Mar 3 15:07:48 2014 -0500 fix error dispatch --- lib/Dancer/Plugin/REST.pm | 17 ++++++++--------- t/04_plugin_settings.t | 12 ++++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/lib/Dancer/Plugin/REST.pm b/lib/Dancer/Plugin/REST.pm index 4d538d6..0454404 100644 --- a/lib/Dancer/Plugin/REST.pm +++ b/lib/Dancer/Plugin/REST.pm @@ -31,25 +31,24 @@ register prepare_serializer_for_format => sub { hook 'before' => sub { - my $format = params->{'format'}; - return unless defined $format; + my $format = params->{'format'} + or return; # remember what was there before $default_serializer = setting 'serializer'; - my $serializer = $serializers->{$format}; - unless (defined $serializer) { - return halt( + my $serializer = $serializers->{$format} + or return halt( Dancer::Error->new( code => 404, + title => "unsupported format requested", message => "unsupported format requested: " . $format - ) + )->render ); - } set serializer => $serializer; - my $ct = $content_types->{$format} || setting('content_type'); - content_type $ct; + + content_type $content_types->{$format} || setting('content_type'); }; hook after => sub { diff --git a/t/04_plugin_settings.t b/t/04_plugin_settings.t index 1b3b140..b711699 100644 --- a/t/04_plugin_settings.t +++ b/t/04_plugin_settings.t @@ -18,6 +18,8 @@ my $yaml = YAML::Dump($data); use Dancer::Plugin::REST; set environment => 'test'; + set show_errors => 1; + prepare_serializer_for_format; get '/' => sub { "root" }; @@ -41,17 +43,13 @@ my @tests = ( request => [GET => '/foo.yml'], response => $yaml, }, - { - request => [GET => '/foo.foobar'], - response => qr/unsupported format requested: foobar/ms, - }, { request => [GET => '/'], response => 'root', }, ); -plan tests => scalar(@tests); +plan tests => 6; for my $test ( @tests ) { my $response = dancer_response(@{$test->{request}}); @@ -65,5 +63,7 @@ for my $test ( @tests ) { } } +my $response = dancer_response( GET => '/foo.foobar' ); - +is $response->status => 404, 'error code 404'; +like $response->content => qr/unsupported format requested: foobar/ms; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libdancer-plugin-rest-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list Pkg-perl-cvs-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits