Skip to content

Commit e628b55

Browse files
committed
cleanup
1 parent fcd0e8a commit e628b55

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

services/web/server/tests/unit/isolated/test_exception_handling.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,23 @@
1515
async 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

0 commit comments

Comments
 (0)