[jsonapi] /api/library/*/{id} returns 404 (instead of 500) on not finding item (#1326)

Co-authored-by: whatdoineed2do/Ray <whatdoineed2do@nospam.gmail.com>
This commit is contained in:
whatdoineed2do 2021-10-25 16:36:51 +01:00 committed by GitHub
parent 383146eb35
commit a5f75dab36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -491,13 +491,14 @@ fetch_artists(struct query_params *query_params, json_object *items, int *total)
}
static json_object *
fetch_artist(const char *artist_id)
fetch_artist(bool *notfound, const char *artist_id)
{
struct query_params query_params;
json_object *artist;
struct db_group_info dbgri;
int ret = 0;
*notfound = true;
memset(&query_params, 0, sizeof(struct query_params));
artist = NULL;
@ -512,6 +513,7 @@ fetch_artist(const char *artist_id)
if ((ret = db_query_fetch_group(&query_params, &dbgri)) == 0)
{
artist = artist_to_json(&dbgri);
notfound = false;
}
error:
@ -558,13 +560,15 @@ fetch_albums(struct query_params *query_params, json_object *items, int *total)
}
static json_object *
fetch_album(const char *album_id)
fetch_album(bool *notfound, const char *album_id)
{
struct query_params query_params;
json_object *album;
struct db_group_info dbgri;
int ret = 0;
*notfound = true;
memset(&query_params, 0, sizeof(struct query_params));
album = NULL;
@ -579,6 +583,7 @@ fetch_album(const char *album_id)
if ((ret = db_query_fetch_group(&query_params, &dbgri)) == 0)
{
album = album_to_json(&dbgri);
*notfound = false;
}
error:
@ -621,13 +626,15 @@ fetch_playlists(struct query_params *query_params, json_object *items, int *tota
}
static json_object *
fetch_playlist(uint32_t playlist_id)
fetch_playlist(bool *notfound, uint32_t playlist_id)
{
struct query_params query_params;
json_object *playlist;
struct db_playlist_info dbpli;
int ret = 0;
*notfound = true;
memset(&query_params, 0, sizeof(struct query_params));
playlist = NULL;
@ -642,6 +649,7 @@ fetch_playlist(uint32_t playlist_id)
if (((ret = db_query_fetch_pl(&query_params, &dbpli)) == 0) && (dbpli.id))
{
playlist = playlist_to_json(&dbpli);
*notfound = false;
}
error:
@ -3003,13 +3011,14 @@ jsonapi_reply_library_artist(struct httpd_request *hreq)
const char *artist_id;
json_object *reply;
int ret = 0;
bool notfound = false;
if (!is_modified(hreq->req, DB_ADMIN_DB_UPDATE))
return HTTP_NOTMODIFIED;
artist_id = hreq->uri_parsed->path_parts[3];
reply = fetch_artist(artist_id);
reply = fetch_artist(&notfound, artist_id);
if (!reply)
{
ret = -1;
@ -3024,7 +3033,7 @@ jsonapi_reply_library_artist(struct httpd_request *hreq)
jparse_free(reply);
if (ret < 0)
return HTTP_INTERNAL;
return notfound ? HTTP_NOTFOUND : HTTP_INTERNAL;
return HTTP_OK;
}
@ -3151,13 +3160,14 @@ jsonapi_reply_library_album(struct httpd_request *hreq)
const char *album_id;
json_object *reply;
int ret = 0;
bool notfound = false;
if (!is_modified(hreq->req, DB_ADMIN_DB_UPDATE))
return HTTP_NOTMODIFIED;
album_id = hreq->uri_parsed->path_parts[3];
reply = fetch_album(album_id);
reply = fetch_album(&notfound, album_id);
if (!reply)
{
ret = -1;
@ -3172,7 +3182,7 @@ jsonapi_reply_library_album(struct httpd_request *hreq)
jparse_free(reply);
if (ret < 0)
return HTTP_INTERNAL;
return notfound ? HTTP_NOTFOUND : HTTP_INTERNAL;
return HTTP_OK;
}
@ -3269,6 +3279,7 @@ jsonapi_reply_library_tracks_get_byid(struct httpd_request *hreq)
struct db_media_file_info dbmfi;
json_object *reply = NULL;
int ret = 0;
bool notfound = false;
if (!is_modified(hreq->req, DB_ADMIN_DB_MODIFIED))
return HTTP_NOTMODIFIED;
@ -3292,6 +3303,7 @@ jsonapi_reply_library_tracks_get_byid(struct httpd_request *hreq)
{
DPRINTF(E_LOG, L_WEB, "Track with id '%s' not found.\n", track_id);
ret = -1;
notfound = true;
goto error;
}
@ -3307,7 +3319,7 @@ jsonapi_reply_library_tracks_get_byid(struct httpd_request *hreq)
jparse_free(reply);
if (ret < 0)
return HTTP_INTERNAL;
return notfound ? HTTP_NOTFOUND : HTTP_INTERNAL;
return HTTP_OK;
}
@ -3577,6 +3589,7 @@ jsonapi_reply_library_playlist_get(struct httpd_request *hreq)
uint32_t playlist_id;
json_object *reply = NULL;
int ret = 0;
bool notfound = false;
if (!is_modified(hreq->req, DB_ADMIN_DB_UPDATE))
return HTTP_NOTMODIFIED;
@ -3599,7 +3612,7 @@ jsonapi_reply_library_playlist_get(struct httpd_request *hreq)
}
else
{
reply = fetch_playlist(playlist_id);
reply = fetch_playlist(&notfound, playlist_id);
}
if (!reply)
@ -3616,7 +3629,7 @@ jsonapi_reply_library_playlist_get(struct httpd_request *hreq)
jparse_free(reply);
if (ret < 0)
return HTTP_INTERNAL;
return notfound ? HTTP_NOTFOUND : HTTP_INTERNAL;
return HTTP_OK;
}