Add feedback for failed scrobble submission, fix GH-297

This commit is contained in:
krateng 2023-12-28 02:26:32 +01:00
parent 472281230c
commit ea6e27de5c
3 changed files with 19 additions and 1 deletions

View File

@ -82,6 +82,14 @@ errors = {
'desc':"This entity does not exist in the database."
}
}),
database.exceptions.DuplicateTimestamp: lambda e: (409,{
"status":"error",
"error":{
'type':'duplicate_timestamp',
'value':e.rejected_scrobble,
'desc':"A scrobble is already registered with this timestamp."
}
}),
images.MalformedB64: lambda e: (400,{
"status":"failure",
"error":{

View File

@ -14,6 +14,13 @@ class ArtistExists(EntityExists):
class AlbumExists(EntityExists):
pass
class DuplicateTimestamp(Exception):
def __init__(self,existing_scrobble,rejected_scrobble):
self.existing_scrobble = existing_scrobble
self.rejected_scrobble = rejected_scrobble
class DatabaseNotBuilt(HTTPError):
def __init__(self):
super().__init__(

View File

@ -328,7 +328,10 @@ def album_dict_to_db(info,dbconn=None):
@connection_provider
def add_scrobble(scrobbledict,update_album=False,dbconn=None):
add_scrobbles([scrobbledict],update_album=update_album,dbconn=dbconn)
_, e = add_scrobbles([scrobbledict],update_album=update_album,dbconn=dbconn)
if e > 0:
raise exc.DuplicateTimestamp(existing_scrobble=None,rejected_scrobble=scrobbledict)
# TODO: actually pass existing scrobble
@connection_provider
def add_scrobbles(scrobbleslist,update_album=False,dbconn=None):