phaidra/phaidra-api

getting members from non existing collection returns empty string instead of json

Closed this issue · 3 comments

yurj commented

$self->render(json => {alerts => $res->{alerts}, metadata => {members => $res->{members}}}, status => $res->{status});

for example:

$ curl -X GET "https://phaidratest.cab.unipd.it/api/collection/1/members"
$ 
$ curl -X GET "https://services.phaidra.univie.ac.at/api/collection/o:23213123/members"
$

the call return a json for non collection content types:

$ curl -X GET "https://services.phaidra.univie.ac.at/api/collection/o:1433423/members"
{"alerts":[],"metadata":{"members":[]}}$

the call should return at least an empty json ({}) but would be better to return:

{"alerts":[],"metadata":{"members":[]}}

Related log messages:

[2022/04/15 10:34:34] [ERROR] [6224] [error] Collection->get_members: Cannot get lastModifiedDate!
[2022/04/15 10:34:34] [ERROR] [6224] [error] must specify key at /usr/local/phaidra/phaidra-api/PhaidraAPI/Model/Collection.pm line 217.

I also found that getting members of empty collections isn't cached, probably because $c->app->chi->set($cachekey, $cached_members, '1 day'); doesn't set the cache element when its value is undefined. I think it's not a big deal.