From: LNATION Date: Wed, 3 Jan 2018 07:55:31 +0000 (+0700) Subject: make the missing data handler exception slightly more useful X-Git-Tag: 5.90116~6^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=c63ec19d30f54b6fa44dff3e448108ab2e15ae84 make the missing data handler exception slightly more useful --- diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 1306b94..c4d7764 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -132,8 +132,11 @@ sub _build_body_data { my $fh = $self->body; local $_ = $fh; return $self->data_handlers->{$match}->($fh, $self); - } else { - Catalyst::Exception->throw("$content_type is does not have an available data handler"); + } else { + Catalyst::Exception->throw( + sprintf '%s does not have an available data handler. Valid data_handlers are %s.', + $content_type, join ', ', sort keys %{$self->data_handlers} + ); } } diff --git a/t/data_handler.t b/t/data_handler.t index 0d4af33..65af48a 100644 --- a/t/data_handler.t +++ b/t/data_handler.t @@ -7,6 +7,7 @@ use FindBin; use Test::More; use HTTP::Request::Common; use JSON::MaybeXS; +use Capture::Tiny qw/:all/; use lib "$FindBin::Bin/lib"; use Catalyst::Test 'TestDataHandlers'; @@ -30,5 +31,13 @@ ok my($res, $c) = ctx_request('/'); is $response->content, 'expected', 'expected content body'; } +{ + my $out; + local *STDERR; + open(STDERR, ">", \$out) or die "Can't open STDERR: $!"; + ok my $req = POST $c->uri_for_action('/test_nested_for'), 'Content-Type' => 'multipart/form-data', Content => { die => "a horrible death" }; + ok my $response = request $req; + is($out, "[error] multipart/form-data does not have an available data handler. Valid data_handlers are application/json, application/x-www-form-urlencoded.\n", 'yep we throw the slightly more usefull error'); +} done_testing;