|
| 1 | +class HTTPError(Exception): |
| 2 | + ''' Base of all other errors''' |
| 3 | + def __init__(self,error): |
| 4 | + self.code = error.code |
| 5 | + self.reason = error.reason |
| 6 | + #self.headers = error.headers |
| 7 | + |
| 8 | +class BadRequestsError(HTTPError): |
| 9 | + pass |
| 10 | + |
| 11 | +class UnauthorizedError(HTTPError): |
| 12 | + pass |
| 13 | + |
| 14 | +class ForbiddenError(HTTPError): |
| 15 | + pass |
| 16 | + |
| 17 | +class NotFoundError(HTTPError): |
| 18 | + pass |
| 19 | + |
| 20 | +class MethodNotAllowedError(HTTPError): |
| 21 | + pass |
| 22 | + |
| 23 | +class PayloadTooLargeError(HTTPError): |
| 24 | + pass |
| 25 | + |
| 26 | +class UnsupportedMediaTypeError(HTTPError): |
| 27 | + pass |
| 28 | + |
| 29 | +class TooManyRequestsError(HTTPError): |
| 30 | + pass |
| 31 | + |
| 32 | +class InternalServerError(HTTPError): |
| 33 | + pass |
| 34 | + |
| 35 | +class ServiceUnavailableError(HTTPError): |
| 36 | + pass |
| 37 | + |
| 38 | +err_dict = { 400 : BadRequestsError, |
| 39 | + 401 : UnauthorizedError, |
| 40 | + 403 : ForbiddenError, |
| 41 | + 404 : NotFoundError, |
| 42 | + 405 : MethodNotAllowedError, |
| 43 | + 413 : PayloadTooLargeError, |
| 44 | + 415 : UnsupportedMediaTypeError, |
| 45 | + 429 : TooManyRequestsError, |
| 46 | + 500 : InternalServerError, |
| 47 | + 503 : ServiceUnavailableError |
| 48 | +} |
| 49 | + |
| 50 | +def handle_error(error): |
| 51 | + exc = err_dict[error.code](error) |
| 52 | + exc.__cause__ = None |
| 53 | + raise exc |
0 commit comments