WIP: Custom exceptions handling and new models
This commit is contained in:
46
classes/exceptions.py
Normal file
46
classes/exceptions.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from typing import Literal
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
class AlbumNotFoundError(Exception):
|
||||
def __init__(self, id: str):
|
||||
self.id = id
|
||||
self.openapi = {
|
||||
"description": "Album does not exist",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Could not find an album with id '{id}'."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AlbumAlreadyExistsError(Exception):
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
self.openapi = {
|
||||
"description": "Album already exists",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Album with name '{name}' already exists."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AlbumIncorrectError(Exception):
|
||||
def __init__(self, place: Literal["name", "title"], error: str) -> None:
|
||||
self.place = place
|
||||
self.error = error
|
||||
self.openapi = {
|
||||
"description": "Album name/title invalid",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Album {name/title} invalid: {error}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
from typing import Union
|
||||
from typing import Dict, List, Literal, Union
|
||||
from pydantic import BaseModel
|
||||
|
||||
class Photo(BaseModel):
|
||||
@@ -7,21 +7,45 @@ class Photo(BaseModel):
|
||||
hash: str
|
||||
filename: str
|
||||
|
||||
class PhotoSearch(BaseModel):
|
||||
id: str
|
||||
filename: str
|
||||
caption: Union[str, None]
|
||||
|
||||
class Video(BaseModel):
|
||||
id: str
|
||||
album: str
|
||||
hash: str
|
||||
filename: str
|
||||
|
||||
class VideoSearch(BaseModel):
|
||||
id: str
|
||||
filename: str
|
||||
caption: Union[str, None]
|
||||
|
||||
class Album(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
title: str
|
||||
|
||||
class AlbumSearch(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
title: str
|
||||
|
||||
class AlbumModified(BaseModel):
|
||||
name: str
|
||||
title: str
|
||||
cover: Union[str, None]
|
||||
|
||||
class SearchResults(BaseModel):
|
||||
results: list
|
||||
next_page: Union[str, None] = None
|
||||
class SearchResultsAlbum(BaseModel):
|
||||
results: List[Album]
|
||||
next_page: Union[str, None]
|
||||
|
||||
class SearchResultsPhoto(BaseModel):
|
||||
results: List[PhotoSearch]
|
||||
next_page: Union[str, None]
|
||||
|
||||
class SearchResultsVideo(BaseModel):
|
||||
results: List[VideoSearch]
|
||||
next_page: Union[str, None]
|
Reference in New Issue
Block a user