Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Cro/HTTP/Router.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@ module Cro::HTTP::Router {
my @*BIND-FAILS;
my $log-timeline-task = $request.annotations<log-timeline>;
my $routing-outcome = Cro::HTTP::LogTimeline::Route.log: $log-timeline-task, -> {
CATCH {
when X::Cro::Uri::ParseError {
emit Cro::HTTP::Response.new(:500status, :$request);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be 400 (Bad Request), since it's the client's fault.

next;
}
}
$request.path ~~ $!path-matcher
}
with $routing-outcome {
Expand Down
6 changes: 6 additions & 0 deletions t/http-router.t
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ throws-like { bad-request }, X::Cro::HTTP::Router::OnlyInHandler, what => 'bad-r
ok $r ~~ Cro::HTTP::Response, 'No matching route gets a HTTP response';
is $r.status, '404', 'Status code when no matching route is 404';
}

$source.emit(Cro::HTTP::Request.new(:method<GET>, :target<example[1].jpg>));
given $responses.receive -> $r {
ok $r ~~ Cro::HTTP::Response, 'No matching route gets a HTTP response';
is $r.status, '500', 'Status code uri is invalid is 500';
}
}

{
Expand Down