Exceptions

This commit is contained in:
krateng 2023-10-28 13:11:45 +02:00
parent abc48a04c8
commit 5524ee5aef
2 changed files with 13 additions and 3 deletions

View File

@ -72,6 +72,14 @@ errors = {
'desc':"The database is being upgraded. Please try again later." 'desc':"The database is being upgraded. Please try again later."
} }
}), }),
database.exceptions.EntityDoesNotExist: lambda e: (404,{
"status":"error",
"error":{
'type':'entity_does_not_exist',
'value':e.entitydict,
'desc':"This entity does not exist in the database."
}
}),
images.MalformedB64: lambda e: (400,{ images.MalformedB64: lambda e: (400,{
"status":"failure", "status":"failure",
"error":{ "error":{

View File

@ -11,6 +11,8 @@ class TrackExists(EntityExists):
class ArtistExists(EntityExists): class ArtistExists(EntityExists):
pass pass
class AlbumExists(EntityExists):
pass
class DatabaseNotBuilt(HTTPError): class DatabaseNotBuilt(HTTPError):
def __init__(self): def __init__(self):
@ -30,11 +32,11 @@ class MissingEntityParameter(Exception):
class EntityDoesNotExist(HTTPError): class EntityDoesNotExist(HTTPError):
entitytype = 'Entity' entitytype = 'Entity'
def __init__(self,name): def __init__(self,entitydict):
self.entityname = name self.entitydict = entitydict
super().__init__( super().__init__(
status=404, status=404,
body=f"The {self.entitytype} '{self.entityname}' does not exist in the database." body=f"The {self.entitytype} '{self.entitydict}' does not exist in the database."
) )
class ArtistDoesNotExist(EntityDoesNotExist): class ArtistDoesNotExist(EntityDoesNotExist):