-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrors.py
More file actions
69 lines (46 loc) · 1.65 KB
/
errors.py
File metadata and controls
69 lines (46 loc) · 1.65 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
from http import HTTPStatus
from fishjam._openapi_client.models import Error
from fishjam._openapi_client.types import Response
class HTTPError(Exception):
""""""
@staticmethod
def from_response(response: Response[Error]):
"""@private"""
if not response.parsed:
raise RuntimeError("Got endpoint error reponse without parsed field")
errors = response.parsed.errors
match response.status_code:
case HTTPStatus.BAD_REQUEST:
return BadRequestError(errors)
case HTTPStatus.UNAUTHORIZED:
return UnauthorizedError(errors)
case HTTPStatus.NOT_FOUND:
return NotFoundError(errors)
case HTTPStatus.SERVICE_UNAVAILABLE:
return ServiceUnavailableError(errors)
case _:
return InternalServerError(errors)
class BadRequestError(HTTPError):
def __init__(self, errors):
"""@private"""
super().__init__(errors)
class UnauthorizedError(HTTPError):
def __init__(self, errors):
"""@private"""
super().__init__(errors)
class NotFoundError(HTTPError):
def __init__(self, errors):
"""@private"""
super().__init__(errors)
class ServiceUnavailableError(HTTPError):
def __init__(self, errors):
"""@private"""
super().__init__(errors)
class InternalServerError(HTTPError):
def __init__(self, errors):
"""@private"""
super().__init__(errors)
class MissingFishjamIdError(Exception):
def __init__(self, message: str = "Missing Fishjam ID"):
"""@private"""
super().__init__(message)