File size: 1,218 Bytes
f66cd72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Typed pipeline errors that map 1:1 to the codes in docs/api-contract.md."""


class KrattError(Exception):
    """A user-facing failure with a contract error code and HTTP status."""

    def __init__(self, code: str, message: str, status: int):
        super().__init__(message)
        self.code = code
        self.message = message
        self.status = status


def invalid_url() -> KrattError:
    return KrattError(
        "invalid_url",
        "The provided URL is not a valid YouTube video link.",
        400,
    )


def video_not_found() -> KrattError:
    return KrattError(
        "video_not_found",
        "This video doesn't exist or is private.",
        404,
    )


def no_comments() -> KrattError:
    return KrattError(
        "no_comments",
        "This video has comments disabled or has zero comments.",
        422,
    )


def youtube_quota_exceeded() -> KrattError:
    return KrattError(
        "youtube_quota_exceeded",
        "YouTube's API quota has been hit. Please try again in a bit.",
        503,
    )


def internal_error() -> KrattError:
    return KrattError(
        "internal_error",
        "Something went wrong on our end. Please try again.",
        500,
    )