Fishjam Python Server SDK
 1from http import HTTPStatus
 2
 3from fishjam._openapi_client.models import Error
 4from fishjam._openapi_client.types import Response
 5
 6
 7class HTTPError(Exception):
 8    """"""
 9
10    @staticmethod
11    def from_response(response: Response[Error]):
12        """@private"""
13        if not response.parsed:
14            raise RuntimeError("Got endpoint error reponse without parsed field")
15
16        errors = response.parsed.errors
17
18        match response.status_code:
19            case HTTPStatus.BAD_REQUEST:
20                return BadRequestError(errors)
21
22            case HTTPStatus.UNAUTHORIZED:
23                return UnauthorizedError(errors)
24
25            case HTTPStatus.NOT_FOUND:
26                return NotFoundError(errors)
27
28            case HTTPStatus.SERVICE_UNAVAILABLE:
29                return ServiceUnavailableError(errors)
30
31            case HTTPStatus.CONFLICT:
32                return ConflictError(errors)
33
34            case _:
35                return InternalServerError(errors)
36
37
38class BadRequestError(HTTPError):
39    def __init__(self, errors):
40        """@private"""
41        super().__init__(errors)
42
43
44class UnauthorizedError(HTTPError):
45    def __init__(self, errors):
46        """@private"""
47        super().__init__(errors)
48
49
50class NotFoundError(HTTPError):
51    def __init__(self, errors):
52        """@private"""
53        super().__init__(errors)
54
55
56class ServiceUnavailableError(HTTPError):
57    def __init__(self, errors):
58        """@private"""
59        super().__init__(errors)
60
61
62class InternalServerError(HTTPError):
63    def __init__(self, errors):
64        """@private"""
65        super().__init__(errors)
66
67
68class ConflictError(HTTPError):
69    def __init__(self, errors):
70        """@private"""
71        super().__init__(errors)
class HTTPError(builtins.Exception):
 8class HTTPError(Exception):
 9    """"""
10
11    @staticmethod
12    def from_response(response: Response[Error]):
13        """@private"""
14        if not response.parsed:
15            raise RuntimeError("Got endpoint error reponse without parsed field")
16
17        errors = response.parsed.errors
18
19        match response.status_code:
20            case HTTPStatus.BAD_REQUEST:
21                return BadRequestError(errors)
22
23            case HTTPStatus.UNAUTHORIZED:
24                return UnauthorizedError(errors)
25
26            case HTTPStatus.NOT_FOUND:
27                return NotFoundError(errors)
28
29            case HTTPStatus.SERVICE_UNAVAILABLE:
30                return ServiceUnavailableError(errors)
31
32            case HTTPStatus.CONFLICT:
33                return ConflictError(errors)
34
35            case _:
36                return InternalServerError(errors)
Inherited Members
builtins.BaseException
BaseException
with_traceback
add_note
args
class BadRequestError(HTTPError):
39class BadRequestError(HTTPError):
40    def __init__(self, errors):
41        """@private"""
42        super().__init__(errors)
Inherited Members
builtins.BaseException
with_traceback
add_note
args
class UnauthorizedError(HTTPError):
45class UnauthorizedError(HTTPError):
46    def __init__(self, errors):
47        """@private"""
48        super().__init__(errors)
Inherited Members
builtins.BaseException
with_traceback
add_note
args
class NotFoundError(HTTPError):
51class NotFoundError(HTTPError):
52    def __init__(self, errors):
53        """@private"""
54        super().__init__(errors)
Inherited Members
builtins.BaseException
with_traceback
add_note
args
class ServiceUnavailableError(HTTPError):
57class ServiceUnavailableError(HTTPError):
58    def __init__(self, errors):
59        """@private"""
60        super().__init__(errors)
Inherited Members
builtins.BaseException
with_traceback
add_note
args
class InternalServerError(HTTPError):
63class InternalServerError(HTTPError):
64    def __init__(self, errors):
65        """@private"""
66        super().__init__(errors)
Inherited Members
builtins.BaseException
with_traceback
add_note
args
class ConflictError(HTTPError):
69class ConflictError(HTTPError):
70    def __init__(self, errors):
71        """@private"""
72        super().__init__(errors)
Inherited Members
builtins.BaseException
with_traceback
add_note
args