forked from aws-powertools/powertools-lambda-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
123 lines (95 loc) · 3.16 KB
/
exceptions.py
File metadata and controls
123 lines (95 loc) · 3.16 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from __future__ import annotations
from http import HTTPStatus
class ServiceError(Exception):
"""Powertools class HTTP Service Error"""
def __init__(self, status_code: int, msg: str | dict):
"""
Parameters
----------
status_code: int
Http status code
msg: str | dict
Error message. Can be a string or a dictionary
"""
self.status_code = status_code
self.msg = msg
class BadRequestError(ServiceError):
"""Powertools class Bad Request Error (400)"""
def __init__(self, msg: str | dict):
"""
Parameters
----------
msg : str | dict
Error message. Can be a string or a dictionary.
"""
super().__init__(HTTPStatus.BAD_REQUEST, msg)
class UnauthorizedError(ServiceError):
"""Powertools class Unauthorized Error (401)"""
def __init__(self, msg: str | dict):
"""
Parameters
----------
msg : str | dict
Error message. Can be a string or a dictionary.
"""
super().__init__(HTTPStatus.UNAUTHORIZED, msg)
class ForbiddenError(ServiceError):
"""Powertools class Forbidden Error (403)"""
def __init__(self, msg: str | dict):
"""
Parameters
----------
msg : str | dict
Error message. Can be a string or a dictionary.
"""
super().__init__(HTTPStatus.FORBIDDEN, msg)
class NotFoundError(ServiceError):
"""Powertools class Not Found Error (404)"""
def __init__(self, msg: str | dict = "Not found"):
"""
Parameters
----------
msg : str | dict
Error message. Can be a string or a dictionary.
"""
super().__init__(HTTPStatus.NOT_FOUND, msg)
class RequestTimeoutError(ServiceError):
"""Powertools class Request Timeout Error (408)"""
def __init__(self, msg: str | dict):
"""
Parameters
----------
msg : str | dict
Error message. Can be a string or a dictionary.
"""
super().__init__(HTTPStatus.REQUEST_TIMEOUT, msg)
class RequestEntityTooLargeError(ServiceError):
"""Powertools class Request Entity Too Large Error (413)"""
def __init__(self, msg: str | dict):
"""
Parameters
----------
msg : str | dict
Error message. Can be a string or a dictionary.
"""
super().__init__(HTTPStatus.REQUEST_ENTITY_TOO_LARGE, msg)
class InternalServerError(ServiceError):
"""Powertools class Internal Server Error (500)"""
def __init__(self, message: str | dict):
"""
Parameters
----------
msg : str | dict
Error message. Can be a string or a dictionary.
"""
super().__init__(HTTPStatus.INTERNAL_SERVER_ERROR, message)
class ServiceUnavailableError(ServiceError):
"""Powertools class Service Unavailable Error (503)"""
def __init__(self, msg: str | dict):
"""
Parameters
----------
msg : str | dict
Error message. Can be a string or a dictionary.
"""
super().__init__(HTTPStatus.SERVICE_UNAVAILABLE, msg)