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