forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.py
73 lines (46 loc) · 1.9 KB
/
exceptions.py
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
70
71
72
73
from http import HTTPStatus
class ServiceError(Exception):
"""API Gateway and ALB HTTP Service Error"""
def __init__(self, status_code: int, msg: str):
"""
Parameters
----------
status_code: int
Http status code
msg: str
Error message
"""
self.status_code = status_code
self.msg = msg
class BadRequestError(ServiceError):
"""API Gateway and ALB Bad Request Error (400)"""
def __init__(self, msg: str):
super().__init__(HTTPStatus.BAD_REQUEST, msg)
class UnauthorizedError(ServiceError):
"""API Gateway and ALB Unauthorized Error (401)"""
def __init__(self, msg: str):
super().__init__(HTTPStatus.UNAUTHORIZED, msg)
class ForbiddenError(ServiceError):
"""API Gateway and ALB Forbidden Error (403)"""
def __init__(self, msg: str):
super().__init__(HTTPStatus.FORBIDDEN, msg)
class NotFoundError(ServiceError):
"""API Gateway and ALB Not Found Error (404)"""
def __init__(self, msg: str = "Not found"):
super().__init__(HTTPStatus.NOT_FOUND, msg)
class RequestTimeoutError(ServiceError):
"""API Gateway and ALB Request Timeout Error (408)"""
def __init__(self, msg: str):
super().__init__(HTTPStatus.REQUEST_TIMEOUT, msg)
class RequestEntityTooLargeError(ServiceError):
"""API Gateway and ALB Request Entity Too Large Error (413)"""
def __init__(self, msg: str):
super().__init__(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, msg)
class InternalServerError(ServiceError):
"""API Gateway and ALB Internal Server Error (500)"""
def __init__(self, message: str):
super().__init__(HTTPStatus.INTERNAL_SERVER_ERROR, message)
class ServiceUnavailableError(ServiceError):
"""API Gateway and ALB Service Unavailable Error (503)"""
def __init__(self, msg: str):
super().__init__(HTTPStatus.SERVICE_UNAVAILABLE, msg)