WIP: Better error handling
This commit is contained in:
@@ -2,15 +2,31 @@ from typing import Literal
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from modules.utils import configGet
|
||||
|
||||
class AlbumNotFoundError(Exception):
|
||||
def __init__(self, id: str):
|
||||
self.id = id
|
||||
self.openapi = {
|
||||
"description": "Album does not exist",
|
||||
"description": "Album Does Not Exist",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Could not find an album with id '{id}'."
|
||||
"detail": "Could not find album with id '{id}'."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AlbumNameNotFoundError(Exception):
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
self.openapi = {
|
||||
"description": "Album Does Not Exist",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Could not find album with name '{name}'."
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +36,7 @@ class AlbumAlreadyExistsError(Exception):
|
||||
def __init__(self, name: str):
|
||||
self.name = name
|
||||
self.openapi = {
|
||||
"description": "Album already exists",
|
||||
"description": "Album Already Exists",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
@@ -35,7 +51,7 @@ class AlbumIncorrectError(Exception):
|
||||
self.place = place
|
||||
self.error = error
|
||||
self.openapi = {
|
||||
"description": "Album name/title invalid",
|
||||
"description": "Album Name/Title Invalid",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
@@ -43,4 +59,83 @@ class AlbumIncorrectError(Exception):
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PhotoNotFoundError(Exception):
|
||||
def __init__(self, id: str):
|
||||
self.id = id
|
||||
self.openapi = {
|
||||
"description": "Photo Does Not Exist",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Could not find photo with id '{id}'."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SearchPageInvalidError(Exception):
|
||||
def __init__(self):
|
||||
self.openapi = {
|
||||
"description": "Invalid Page",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Parameters 'page' and 'page_size' must be greater or equal to 1."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SearchTokenInvalidError(Exception):
|
||||
def __init__(self):
|
||||
self.openapi = {
|
||||
"description": "Invalid Token",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Invalid search token."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UserEmailCodeInvalid(Exception):
|
||||
def __init__(self):
|
||||
self.openapi = {
|
||||
"description": "Invalid Email Code",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Confirmation code is invalid."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UserAlreadyExists(Exception):
|
||||
def __init__(self):
|
||||
self.openapi = {
|
||||
"description": "User Already Exists",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "User with this username already exists."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class UserCredentialsInvalid(Exception):
|
||||
def __init__(self):
|
||||
self.openapi = {
|
||||
"description": "Invalid Credentials",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"detail": "Invalid credentials."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -7,6 +7,11 @@ class Photo(BaseModel):
|
||||
hash: str
|
||||
filename: str
|
||||
|
||||
class PhotoPublic(BaseModel):
|
||||
id: str
|
||||
caption: str
|
||||
filename: str
|
||||
|
||||
class PhotoSearch(BaseModel):
|
||||
id: str
|
||||
filename: str
|
||||
|
Reference in New Issue
Block a user