File size: 1,764 Bytes
936f0bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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)