api/v0: improve error conditions
Return an HTTP 404 when no media is found and an HTTP 400 when some of the requested tags aren't found.
This commit is contained in:
parent
fa6f642ca2
commit
9d8b300d11
1 changed files with 9 additions and 0 deletions
|
@ -20,6 +20,10 @@ sub _list_with_tags ($self, $page, @tags)
|
|||
my $paged_media_ids = $self->media_model->with_all_tags(@tags)
|
||||
->page($page);
|
||||
my @media_ids = map {$_->{media_id}} $paged_media_ids->fetchall->@*;
|
||||
return $self->render(
|
||||
json => {error => "No matching media found."},
|
||||
status => 404,
|
||||
) if @media_ids == 0;
|
||||
|
||||
return $self->render(json => {
|
||||
media => $self->media_model->get(@media_ids)->page($page)
|
||||
|
@ -55,6 +59,11 @@ sub list ($self)
|
|||
@tag_ids = map {$_->{id}} $self->tags_model
|
||||
->get(display => [@tags])->fetchall->@* if @tags > 0;
|
||||
|
||||
return $self->render(
|
||||
json => {error => "Some of the requested tags don't exist."},
|
||||
status => 400,
|
||||
) if @tag_ids != @tags && @tags > 0;
|
||||
|
||||
return @tags == 0 ?
|
||||
$self->_list_no_tags($page) :
|
||||
$self->_list_with_tags($page, @tag_ids);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue