File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,13 +14,26 @@ class APIExceptionHandler:
1414 @staticmethod
1515 async def validation_error_handler (request : Request , exc : RequestValidationError ):
1616 """Handle request validation errors."""
17- logger .error (f"Validation error: { exc .errors ()} " )
17+ errors = exc .errors ()
18+ path = request .url .path
19+ method = request .method
20+
21+ readable_errors = []
22+ for err in errors :
23+ loc = " -> " .join (str (loc_i ) for loc_i in err .get ("loc" , []))
24+ readable_errors .append (
25+ f"[{ loc } ] { err .get ('msg' , 'unknown error' )} (type: { err .get ('type' , 'unknown' )} )"
26+ )
27+
28+ logger .error (
29+ f"Validation error on { method } { path } : { readable_errors } , raw errors: { errors } "
30+ )
1831 return JSONResponse (
1932 status_code = 422 ,
2033 content = {
2134 "code" : 422 ,
22- "message" : "Parameter validation error" ,
23- "detail" : exc . errors () ,
35+ "message" : f "Parameter validation error on { method } { path } : { '; ' . join ( readable_errors ) } " ,
36+ "detail" : errors ,
2437 "data" : None ,
2538 },
2639 )
You can’t perform that action at this time.
0 commit comments