From 7580478ac3be6bf2e6d2c30aca7c67711245704c Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 16 Feb 2023 15:32:56 +0100 Subject: [PATCH] Added docstrings --- classes/exceptions.py | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/classes/exceptions.py b/classes/exceptions.py index 3a4549a..926cf8a 100644 --- a/classes/exceptions.py +++ b/classes/exceptions.py @@ -2,6 +2,7 @@ from typing import Literal class AlbumNotFoundError(Exception): + """Raises HTTP 404 if no album with this ID found.""" def __init__(self, id: str): self.id = id self.openapi = { @@ -16,6 +17,7 @@ class AlbumNotFoundError(Exception): } class AlbumNameNotFoundError(Exception): + """Raises HTTP 404 if no album with this name found.""" def __init__(self, name: str): self.name = name self.openapi = { @@ -30,6 +32,7 @@ class AlbumNameNotFoundError(Exception): } class AlbumAlreadyExistsError(Exception): + """Raises HTTP 409 if album with this name already exists.""" def __init__(self, name: str): self.name = name self.openapi = { @@ -44,6 +47,7 @@ class AlbumAlreadyExistsError(Exception): } class AlbumIncorrectError(Exception): + """Raises HTTP 406 if album's title or name is invalid.""" def __init__(self, place: Literal["name", "title"], error: str) -> None: self.place = place self.error = error @@ -59,6 +63,7 @@ class AlbumIncorrectError(Exception): } class PhotoNotFoundError(Exception): + """Raises HTTP 404 if no photo with this ID found.""" def __init__(self, id: str): self.id = id self.openapi = { @@ -72,7 +77,51 @@ class PhotoNotFoundError(Exception): } } +class PhotoSearchQueryEmptyError(Exception): + """Raises HTTP 422 if no photo search query provided.""" + def __init__(self): + self.openapi = { + "description": "Invalid Query", + "content": { + "application/json": { + "example": { + "detail": "You must provide query, caption or coordinates to look for photos." + } + } + } + } + +class VideoNotFoundError(Exception): + """Raises HTTP 404 if no video with this ID found.""" + def __init__(self, id: str): + self.id = id + self.openapi = { + "description": "Video Does Not Exist", + "content": { + "application/json": { + "example": { + "detail": "Could not find video with id '{id}'." + } + } + } + } + +class VideoSearchQueryEmptyError(Exception): + """Raises HTTP 422 if no video search query provided.""" + def __init__(self): + self.openapi = { + "description": "Invalid Query", + "content": { + "application/json": { + "example": { + "detail": "You must provide query or caption to look for videos." + } + } + } + } + class SearchPageInvalidError(Exception): + """Raises HTTP 400 if page or page size are not in valid range.""" def __init__(self): self.openapi = { "description": "Invalid Page", @@ -86,6 +135,7 @@ class SearchPageInvalidError(Exception): } class SearchTokenInvalidError(Exception): + """Raises HTTP 401 if search token is not valid.""" def __init__(self): self.openapi = { "description": "Invalid Token", @@ -99,6 +149,7 @@ class SearchTokenInvalidError(Exception): } class UserEmailCodeInvalid(Exception): + """Raises HTTP 400 if email confirmation code is not valid.""" def __init__(self): self.openapi = { "description": "Invalid Email Code", @@ -112,6 +163,7 @@ class UserEmailCodeInvalid(Exception): } class UserAlreadyExists(Exception): + """Raises HTTP 409 if user with this name already exists.""" def __init__(self): self.openapi = { "description": "User Already Exists", @@ -125,6 +177,7 @@ class UserAlreadyExists(Exception): } class UserCredentialsInvalid(Exception): + """Raises HTTP 401 if user credentials are not valid.""" def __init__(self): self.openapi = { "description": "Invalid Credentials",