1- from json import loads
1+ from pydantic import BaseModel
22
3- from pydantic import BaseModel , ValidationError
4-
5- from lilya import status
6- from lilya .requests import Request
7- from lilya .responses import JSONResponse
83from lilya .routing import Path
94from lilya .testclient import create_client
105from tests .encoders .settings import EncoderSettings
116
127
13- async def validation_error_exception_handler (
14- request : Request , exc : ValidationError
15- ) -> JSONResponse : # pragma: no cover
16- """
17- This handler is to be used when a pydantic validation error is triggered during the logic
18- of a code block and not the definition of a handler.
19-
20- This is different from validation_error_exception_handler
21- """
22- status_code = status .HTTP_422_UNPROCESSABLE_ENTITY
23- return JSONResponse ({"detail" : loads (exc .json ())}, status_code = status_code )
24-
25-
268class User (BaseModel ):
279 name : str
2810 age : int
@@ -36,7 +18,6 @@ def test_infer_body_error(test_client_factory):
3618 with create_client (
3719 routes = [Path ("/infer" , handler = process_body , methods = ["POST" ])],
3820 settings_module = EncoderSettings ,
39- exception_handlers = {ValidationError : validation_error_exception_handler },
4021 ) as client :
4122 response = client .post ("/infer" )
4223
0 commit comments