File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
services/web/server/tests/unit/isolated Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 1515async def test_handling_exceptions_decorating_a_route (aiohttp_client : Callable ):
1616
1717 # custom exception handler
18- async def value_error_as_422 (
18+ async def _value_error_as_422 (
1919 request : web .Request , exception : BaseException
2020 ) -> web .Response :
2121 return web .json_response (status = status .HTTP_422_UNPROCESSABLE_ENTITY )
2222
23- # decorator
24- exc_handling = exception_handling_decorator ({ValueError : value_error_as_422 })
23+ # 1. create decorator
24+ exc_handling = exception_handling_decorator (
25+ exception_handlers_map = {
26+ ValueError : _value_error_as_422 ,
27+ }
28+ )
2529
2630 # adding new routes
2731 routes = web .RouteTableDef ()
2832
2933 @routes .get ("/{what}" )
30- @exc_handling # < ----- using decorator
34+ @exc_handling # < ----- 2. using decorator
3135 async def _handler (request : web .Request ):
3236 match request .match_info ["what" ]:
3337 case "ValueError" :
@@ -47,7 +51,7 @@ async def _handler(request: web.Request):
4751 app = web .Application ()
4852 app .add_routes (routes )
4953
50- # testing from the client side
54+ # 3. testing from the client side
5155 client = await aiohttp_client (app )
5256
5357 # success
You can’t perform that action at this time.
0 commit comments