1212from ellar .common .datastructures import UploadFile
1313from ellar .common .exceptions import RequestValidationError
1414from ellar .common .interfaces import IExecutionContext
15+ from ellar .common .logger import request_logger
1516from pydantic .error_wrappers import ErrorWrapper
1617from pydantic .fields import Undefined
1718from pydantic .utils import lenient_issubclass
@@ -32,6 +33,9 @@ def get_received_parameter(
3233 async def resolve_handle (
3334 self , ctx : IExecutionContext , * args : t .Any , ** kwargs : t .Any
3435 ) -> t .Tuple :
36+ request_logger .debug (
37+ f"Resolving Header Parameters - '{ self .__class__ .__name__ } '"
38+ )
3539 received_params = self .get_received_parameter (ctx = ctx )
3640 if (
3741 self .model_field .shape in sequence_shapes
@@ -80,6 +84,7 @@ def get_received_parameter(cls, ctx: IExecutionContext) -> t.Mapping[str, t.Any]
8084 return connection .path_params
8185
8286 async def resolve_handle (self , ctx : IExecutionContext , ** kwargs : t .Any ) -> t .Tuple :
87+ request_logger .debug (f"Resolving Path Parameters - '{ self .__class__ .__name__ } '" )
8388 received_params = self .get_received_parameter (ctx = ctx )
8489 value = received_params .get (str (self .model_field .alias ))
8590 self .assert_field_info ()
@@ -103,6 +108,9 @@ class WsBodyParameterResolver(BaseRouteParameterResolver):
103108 async def resolve_handle (
104109 self , ctx : IExecutionContext , * args : t .Any , body : t .Any , ** kwargs : t .Any
105110 ) -> t .Tuple :
111+ request_logger .debug (
112+ f"Resolving Websocket Body Parameters - '{ self .__class__ .__name__ } '"
113+ )
106114 embed = getattr (self .model_field .field_info , "embed" , False )
107115 received_body = {self .model_field .alias : body }
108116 loc = ("body" ,)
@@ -123,6 +131,9 @@ def __init__(self, *args: t.Any, **kwargs: t.Any):
123131 super ().__init__ (* args , ** kwargs )
124132
125133 async def get_request_body (self , ctx : IExecutionContext ) -> t .Any :
134+ request_logger .debug (
135+ f"Resolving Request Body Parameters - '{ self .__class__ .__name__ } '"
136+ )
126137 try :
127138 request = ctx .switch_to_http_connection ().get_request ()
128139 body_bytes = await request .body ()
@@ -142,8 +153,10 @@ async def get_request_body(self, ctx: IExecutionContext) -> t.Any:
142153 body_bytes = json_body
143154 return body_bytes
144155 except json .JSONDecodeError as e :
156+ request_logger .error ("JSONDecodeError: " , exc_info = True )
145157 raise RequestValidationError ([ErrorWrapper (e , ("body" , e .pos ))]) from e
146- except Exception as e : # pragma: no cover
158+ except Exception as e :
159+ request_logger .error ("Unable to parse the body: " , exc_info = e )
147160 raise HTTPException (
148161 status_code = 400 , detail = "There was an error parsing the body"
149162 ) from e
@@ -170,11 +183,15 @@ async def process_and_validate(
170183 return values , errors_
171184
172185 async def get_request_body (self , ctx : IExecutionContext ) -> t .Any :
186+ request_logger .debug (
187+ f"Resolving Request Form Parameters - '{ self .__class__ .__name__ } '"
188+ )
173189 try :
174190 request = ctx .switch_to_http_connection ().get_request ()
175191 body_bytes = await request .form ()
176192 return body_bytes
177193 except Exception as e :
194+ request_logger .error ("Unable to parse the body: " , exc_info = True )
178195 raise HTTPException (
179196 status_code = 400 , detail = "There was an error parsing the body"
180197 ) from e
0 commit comments