PhotosAPI/classes/exceptions.py

46 lines
1.4 KiB
Python
Raw Normal View History

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}"
}
}
}
}