4
4
import re
5
5
import zlib
6
6
from enum import Enum
7
+ from http import HTTPStatus
7
8
from typing import Any , Callable , Dict , List , Optional , Set , Union
8
9
9
10
from aws_lambda_powertools .shared .json_encoder import Encoder
@@ -35,28 +36,28 @@ class BadRequestError(ServiceError):
35
36
"""Bad Request Error"""
36
37
37
38
def __init__ (self , msg : str ):
38
- super ().__init__ (400 , msg )
39
+ super ().__init__ (HTTPStatus . BAD_REQUEST . value , msg )
39
40
40
41
41
42
class UnauthorizedError (ServiceError ):
42
43
"""Unauthorized Error"""
43
44
44
45
def __init__ (self , msg : str ):
45
- super ().__init__ (401 , msg )
46
+ super ().__init__ (HTTPStatus . UNAUTHORIZED . value , msg )
46
47
47
48
48
49
class NotFoundError (ServiceError ):
49
50
"""Not Found Error"""
50
51
51
52
def __init__ (self , msg : str = "Not found" ):
52
- super ().__init__ (404 , msg )
53
+ super ().__init__ (HTTPStatus . NOT_FOUND . value , msg )
53
54
54
55
55
56
class InternalServerError (ServiceError ):
56
57
"""Internal Server Error"""
57
58
58
59
def __init__ (self , message : str ):
59
- super ().__init__ (500 , message )
60
+ super ().__init__ (HTTPStatus . INTERNAL_SERVER_ERROR . value , message )
60
61
61
62
62
63
class ProxyEventType (Enum ):
@@ -511,10 +512,10 @@ def _not_found(self, method: str) -> ResponseBuilder:
511
512
512
513
return ResponseBuilder (
513
514
Response (
514
- status_code = 404 ,
515
+ status_code = HTTPStatus . NOT_FOUND . value ,
515
516
content_type = APPLICATION_JSON ,
516
517
headers = headers ,
517
- body = self ._json_dump ({"code " : 404 , "message" : "Not found" }),
518
+ body = self ._json_dump ({"statusCode " : HTTPStatus . NOT_FOUND . value , "message" : "Not found" }),
518
519
)
519
520
)
520
521
@@ -527,7 +528,7 @@ def _call_route(self, route: Route, args: Dict[str, str]) -> ResponseBuilder:
527
528
Response (
528
529
status_code = e .status_code ,
529
530
content_type = APPLICATION_JSON ,
530
- body = self ._json_dump ({"code " : e .status_code , "message" : e .msg }),
531
+ body = self ._json_dump ({"statusCode " : e .status_code , "message" : e .msg }),
531
532
),
532
533
route ,
533
534
)
0 commit comments