from __future__ import annotations from fastapi import status class AppException(Exception): def __init__(self, detail: str, status_code: int = status.HTTP_500_INTERNAL_SERVER_ERROR): self.detail = detail self.status_code = status_code super().__init__(detail) class AuthenticationError(AppException): def __init__(self, detail: str = "Unauthorized"): super().__init__(detail, status.HTTP_401_UNAUTHORIZED) class InvalidFileTypeError(AppException): def __init__(self, detail: str = "Unsupported file type"): super().__init__(detail, status.HTTP_415_UNSUPPORTED_MEDIA_TYPE) class FileTooLargeError(AppException): def __init__(self, max_mb: int): super().__init__( f"File exceeds the maximum allowed size of {max_mb} MB", status.HTTP_413_REQUEST_ENTITY_TOO_LARGE, ) class TooManyPagesError(AppException): def __init__(self, max_pages: int): super().__init__( f"PDF exceeds the maximum allowed page count of {max_pages}", status.HTTP_422_UNPROCESSABLE_ENTITY, ) class ConversionError(AppException): def __init__(self, detail: str = "PDF conversion failed"): super().__init__(detail, status.HTTP_500_INTERNAL_SERVER_ERROR) class JobNotFoundError(AppException): def __init__(self, job_id: str): super().__init__(f"Job '{job_id}' not found", status.HTTP_404_NOT_FOUND) class InvalidParameterError(AppException): def __init__(self, detail: str): super().__init__(detail, status.HTTP_422_UNPROCESSABLE_ENTITY) class FileServiceError(AppException): def __init__(self, detail: str = "File upload service error"): super().__init__(detail, status.HTTP_502_BAD_GATEWAY)