1
+ from __future__ import annotations
2
+
1
3
from http import HTTPStatus
2
4
3
5
4
6
class ServiceError (Exception ):
5
7
"""Powertools class HTTP Service Error"""
6
8
7
- def __init__ (self , status_code : int , msg : str ):
9
+ def __init__ (self , status_code : int , msg : str | dict ):
8
10
"""
9
11
Parameters
10
12
----------
11
13
status_code: int
12
14
Http status code
13
- msg: str
14
- Error message
15
+ msg: str | dict
16
+ Error message. Can be a string or a dictionary
15
17
"""
16
18
self .status_code = status_code
17
19
self .msg = msg
@@ -20,54 +22,102 @@ def __init__(self, status_code: int, msg: str):
20
22
class BadRequestError (ServiceError ):
21
23
"""Powertools class Bad Request Error (400)"""
22
24
23
- def __init__ (self , msg : str ):
25
+ def __init__ (self , msg : str | dict ):
26
+ """
27
+ Parameters
28
+ ----------
29
+ msg : str | dict
30
+ Error message. Can be a string or a dictionary.
31
+ """
24
32
super ().__init__ (HTTPStatus .BAD_REQUEST , msg )
25
33
26
34
27
35
class UnauthorizedError (ServiceError ):
28
36
"""Powertools class Unauthorized Error (401)"""
29
37
30
- def __init__ (self , msg : str ):
38
+ def __init__ (self , msg : str | dict ):
39
+ """
40
+ Parameters
41
+ ----------
42
+ msg : str | dict
43
+ Error message. Can be a string or a dictionary.
44
+ """
31
45
super ().__init__ (HTTPStatus .UNAUTHORIZED , msg )
32
46
33
47
34
48
class ForbiddenError (ServiceError ):
35
49
"""Powertools class Forbidden Error (403)"""
36
50
37
- def __init__ (self , msg : str ):
51
+ def __init__ (self , msg : str | dict ):
52
+ """
53
+ Parameters
54
+ ----------
55
+ msg : str | dict
56
+ Error message. Can be a string or a dictionary.
57
+ """
38
58
super ().__init__ (HTTPStatus .FORBIDDEN , msg )
39
59
40
60
41
61
class NotFoundError (ServiceError ):
42
62
"""Powertools class Not Found Error (404)"""
43
63
44
- def __init__ (self , msg : str = "Not found" ):
64
+ def __init__ (self , msg : str | dict = "Not found" ):
65
+ """
66
+ Parameters
67
+ ----------
68
+ msg : str | dict
69
+ Error message. Can be a string or a dictionary.
70
+ """
45
71
super ().__init__ (HTTPStatus .NOT_FOUND , msg )
46
72
47
73
48
74
class RequestTimeoutError (ServiceError ):
49
75
"""Powertools class Request Timeout Error (408)"""
50
76
51
- def __init__ (self , msg : str ):
77
+ def __init__ (self , msg : str | dict ):
78
+ """
79
+ Parameters
80
+ ----------
81
+ msg : str | dict
82
+ Error message. Can be a string or a dictionary.
83
+ """
52
84
super ().__init__ (HTTPStatus .REQUEST_TIMEOUT , msg )
53
85
54
86
55
87
class RequestEntityTooLargeError (ServiceError ):
56
88
"""Powertools class Request Entity Too Large Error (413)"""
57
89
58
- def __init__ (self , msg : str ):
90
+ def __init__ (self , msg : str | dict ):
91
+ """
92
+ Parameters
93
+ ----------
94
+ msg : str | dict
95
+ Error message. Can be a string or a dictionary.
96
+ """
59
97
super ().__init__ (HTTPStatus .REQUEST_ENTITY_TOO_LARGE , msg )
60
98
61
99
62
100
class InternalServerError (ServiceError ):
63
101
"""Powertools class Internal Server Error (500)"""
64
102
65
- def __init__ (self , message : str ):
103
+ def __init__ (self , message : str | dict ):
104
+ """
105
+ Parameters
106
+ ----------
107
+ msg : str | dict
108
+ Error message. Can be a string or a dictionary.
109
+ """
66
110
super ().__init__ (HTTPStatus .INTERNAL_SERVER_ERROR , message )
67
111
68
112
69
113
class ServiceUnavailableError (ServiceError ):
70
114
"""Powertools class Service Unavailable Error (503)"""
71
115
72
- def __init__ (self , msg : str ):
116
+ def __init__ (self , msg : str | dict ):
117
+ """
118
+ Parameters
119
+ ----------
120
+ msg : str | dict
121
+ Error message. Can be a string or a dictionary.
122
+ """
73
123
super ().__init__ (HTTPStatus .SERVICE_UNAVAILABLE , msg )
0 commit comments