from fastapi import HTTPException class LocationNotFoundError(HTTPException): """Raises HTTP 404 if no location with this ID found.""" def __init__(self, id: int): self.id = id self.openapi = { "description": "Location Does Not Exist", "content": { "application/json": { "example": {"detail": "Could not find location with id '{id}'."} } }, } class EntrySearchQueryEmptyError(HTTPException): """Raises HTTP 422 if no entry search query provided.""" def __init__(self): self.openapi = { "description": "Invalid Query", "content": { "application/json": { "example": { "detail": "You must provide location and date(s) to look for entries." } } }, } super().__init__( status_code=422, detail=self.openapi["content"]["application/json"]["example"]["detail"], ) class LocationSearchQueryEmptyError(HTTPException): """Raises HTTP 422 if no location search query provided.""" def __init__(self): self.openapi = { "description": "Invalid Query", "content": { "application/json": { "example": { "detail": "You must provide name or coordinates to look for location." } } }, } super().__init__( status_code=422, detail=self.openapi["content"]["application/json"]["example"]["detail"], ) class SearchLimitInvalidError(HTTPException): """Raises HTTP 400 if search results limit not in valid range.""" def __init__(self): self.openapi = { "description": "Invalid Limit", "content": { "application/json": { "example": { "detail": "Parameter 'limit' must be greater or equal to 1." } } }, } super().__init__( status_code=400, detail=self.openapi["content"]["application/json"]["example"]["detail"], ) class SearchPageInvalidError(HTTPException): """Raises HTTP 400 if page or page size are not in valid range.""" 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." } } }, } super().__init__( status_code=400, detail=self.openapi["content"]["application/json"]["example"]["detail"], )