Skip to content

Commit

Permalink
Merge pull request #1026 from reosarevok/MBS-10133
Browse files Browse the repository at this point in the history
MBS-10133: Clarify "empty query" bad request error
  • Loading branch information
reosarevok committed Jun 5, 2019
2 parents 87f9975 + 646a26b commit 2c06c5f
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 20 deletions.
6 changes: 3 additions & 3 deletions lib/MusicBrainz/Server/Data/WebService.pm
Expand Up @@ -201,11 +201,11 @@ sub xml_search
}

$query =~ s/^ AND //;
# In case we have a blank query
if ($query =~ /^\s*$/)
# In case we have a blank query (only whitespace, or whitespace surrounded by unescaped quotes)
if ($query =~ /^(?:\s*|"\s*")$/)
{
return {
error => "Must specify a least one parameter (other than 'limit', 'offset' or empty 'query') for collections query.",
error => "You submitted a blank search query. You must include a non-blank 'query=' parameter with your search.",
code => HTTP_BAD_REQUEST
};
}
Expand Down
10 changes: 6 additions & 4 deletions lib/MusicBrainz/Server/Test/WS.pm
Expand Up @@ -21,41 +21,43 @@ our @EXPORT_OK = qw(

Readonly our $FORBIDDEN_JSON_RESPONSE => {
error => 'You are not authorized to access this resource.',
help => 'For usage, please see: https://musicbrainz.org/development/mmd',
};

Readonly our $UNAUTHORIZED_JSON_RESPONSE => {
error => 'Your credentials could not be verified. Either you supplied the wrong credentials (e.g., bad password), or your client doesn\'t understand how to supply the credentials required.',
help => 'For usage, please see: https://musicbrainz.org/development/mmd',
};

Readonly our $FORBIDDEN_XML_RESPONSE => <<'EOXML';
<?xml version="1.0" encoding="UTF-8"?>
<error>
<text>You are not authorized to access this resource.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>
EOXML

Readonly our $UNAUTHORIZED_XML_RESPONSE => <<'EOXML';
<?xml version="1.0" encoding="UTF-8"?>
<error>
<text>Your credentials could not be verified. Either you supplied the wrong credentials (e.g., bad password), or your client doesn't understand how to supply the credentials required.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>
EOXML

Readonly our $NOT_FOUND_XML_RESPONSE => <<'EOXML';
<?xml version="1.0" encoding="UTF-8"?>
<error>
<text>Not Found</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>
EOXML

Readonly our $INVALID_MBID_XML_RESPONSE => <<'EOXML';
<?xml version="1.0" encoding="UTF-8"?>
<error>
<text>Invalid mbid.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>
EOXML

Expand Down
5 changes: 4 additions & 1 deletion lib/MusicBrainz/Server/WebService/JSONSerializer.pm
Expand Up @@ -129,7 +129,10 @@ sub autocomplete_editor {
sub output_error {
my ($self, $err) = @_;

return encode_json({ error => $err });
return encode_json({
error => $err,
help => 'For usage, please see: https://musicbrainz.org/development/mmd',
});
}

sub output_success {
Expand Down
2 changes: 1 addition & 1 deletion lib/MusicBrainz/Server/WebService/XMLSerializer.pm
Expand Up @@ -1326,7 +1326,7 @@ sub output_error

return '<?xml version="1.0" encoding="UTF-8"?>' .
$gen->error($gen->text($err), $gen->text(
"For usage, please see: http://musicbrainz.org/development/mmd"));
"For usage, please see: https://musicbrainz.org/development/mmd"));
}

sub output_success
Expand Down
2 changes: 1 addition & 1 deletion t/lib/t/MusicBrainz/Server/Controller/WS/2/Collection.pm
Expand Up @@ -333,7 +333,7 @@ test "collection lookup errors" => sub {
<?xml version="1.0" encoding="UTF-8"?>
<error>
<text>This is not a collection for entity type $entity_type.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>
EOXML
};
Expand Down
Expand Up @@ -21,7 +21,10 @@ test 'errors' => sub {
$mech->get('/ws/2/release?recording=7b1f6e95-b523-43b6-a048-810ea5d463a8');
is($mech->status, 404, 'browse releases via non-existent recording');

is_json($mech->content, encode_json({ error => "Not Found" }));
is_json($mech->content, encode_json({
error => "Not Found",
help => 'For usage, please see: https://musicbrainz.org/development/mmd',
}));
};

test 'browse releases via artist (paging)' => sub {
Expand Down
Expand Up @@ -22,12 +22,16 @@ test 'errors' => sub {
is($mech->status, 400);

is_json($mech->content, encode_json({
error => "coffee is not a valid inc parameter for the artist resource."
error => "coffee is not a valid inc parameter for the artist resource.",
help => 'For usage, please see: https://musicbrainz.org/development/mmd',
}));

$mech->get('/ws/2/artist/00000000-1111-2222-3333-444444444444');
is($mech->status, 404);
is_json($mech->content, encode_json({ error => "Not Found" }));
is_json($mech->content, encode_json({
error => "Not Found",
help => 'For usage, please see: https://musicbrainz.org/development/mmd',
}));
};

test 'basic artist lookup' => sub {
Expand Down
2 changes: 1 addition & 1 deletion t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupArtist.pm
Expand Up @@ -430,7 +430,7 @@ is($mech->status, 400);
is_xml_same($mech->content, q{<?xml version="1.0"?>
<error>
<text>coffee is not a valid inc parameter for the artist resource.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>});

ws_test 'artist lookup with works (using l_artist_work)',
Expand Down
2 changes: 1 addition & 1 deletion t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupDiscID.pm
Expand Up @@ -186,7 +186,7 @@ subtest 'lookup of invalid discid with no toc parameter' => sub {
is_xml_same($mech->content, q{<?xml version="1.0"?>
<error>
<text>Invalid discid.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>});
};

Expand Down
2 changes: 1 addition & 1 deletion t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupEvent.pm
Expand Up @@ -24,7 +24,7 @@ is($mech->status, 400);
is_xml_same($mech->content, q{<?xml version="1.0"?>
<error>
<text>coffee is not a valid inc parameter for the event resource.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>});

ws_test 'basic event lookup',
Expand Down
Expand Up @@ -29,7 +29,7 @@ is($mech->status, 400);
is_xml_same($mech->content, q{<?xml version="1.0"?>
<error>
<text>coffee is not a valid inc parameter for the instrument resource.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>});

ws_test 'basic instrument lookup',
Expand Down
2 changes: 1 addition & 1 deletion t/lib/t/MusicBrainz/Server/Controller/WS/2/LookupSeries.pm
Expand Up @@ -25,7 +25,7 @@ is($mech->status, 400);
is_xml_same($mech->content, q{<?xml version="1.0"?>
<error>
<text>coffee is not a valid inc parameter for the series resource.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>});

ws_test 'basic series lookup',
Expand Down
Expand Up @@ -156,7 +156,7 @@ EOXML
<?xml version="1.0" encoding="UTF-8"?>
<error>
<text>PUT is not allowed on this endpoint.</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>
EOXML
};
Expand Down
2 changes: 1 addition & 1 deletion t/lib/t/MusicBrainz/Server/WebService/Format.pm
Expand Up @@ -108,7 +108,7 @@ test 'webservice request format handling (errors)' => sub {
my $expected = '<?xml version="1.0"?>
<error>
<text>Invalid format. Either set an Accept header (recognized mime types are application/json and application/xml), or include a fmt= argument in the query string (valid values for fmt are json and xml).</text>
<text>For usage, please see: http://musicbrainz.org/development/mmd</text>
<text>For usage, please see: https://musicbrainz.org/development/mmd</text>
</error>';

$Test->note('Accept: application/something-else');
Expand Down

0 comments on commit 2c06c5f

Please sign in to comment.