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 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 _: 33 return InternalServerError(errors) 34 35 36class BadRequestError(HTTPError): 37 def __init__(self, errors): 38 """@private""" 39 super().__init__(errors) 40 41 42class UnauthorizedError(HTTPError): 43 def __init__(self, errors): 44 """@private""" 45 super().__init__(errors) 46 47 48class NotFoundError(HTTPError): 49 def __init__(self, errors): 50 """@private""" 51 super().__init__(errors) 52 53 54class ServiceUnavailableError(HTTPError): 55 def __init__(self, errors): 56 """@private""" 57 super().__init__(errors) 58 59 60class InternalServerError(HTTPError): 61 def __init__(self, errors): 62 """@private""" 63 super().__init__(errors)
class
HTTPError(builtins.Exception):
8class HTTPError(Exception): 9 """""" 10 11 @staticmethod 12 def from_response(response: Response[Error]): 13 """@private""" 14 15 if not response.parsed: 16 raise RuntimeError("Got endpoint error reponse without parsed field") 17 18 errors = response.parsed.errors 19 20 match response.status_code: 21 case HTTPStatus.BAD_REQUEST: 22 return BadRequestError(errors) 23 24 case HTTPStatus.UNAUTHORIZED: 25 return UnauthorizedError(errors) 26 27 case HTTPStatus.NOT_FOUND: 28 return NotFoundError(errors) 29 30 case HTTPStatus.SERVICE_UNAVAILABLE: 31 return ServiceUnavailableError(errors) 32 33 case _: 34 return InternalServerError(errors)
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
37class BadRequestError(HTTPError): 38 def __init__(self, errors): 39 """@private""" 40 super().__init__(errors)
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
49class NotFoundError(HTTPError): 50 def __init__(self, errors): 51 """@private""" 52 super().__init__(errors)
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
61class InternalServerError(HTTPError): 62 def __init__(self, errors): 63 """@private""" 64 super().__init__(errors)
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args