@@ -1388,6 +1388,65 @@ def get_lambda() -> Response:
1388
1388
assert result ["body" ] == json_dump (expected )
1389
1389
1390
1390
1391
+ def test_exception_handler_supports_list (json_dump ):
1392
+ # GIVEN a resolver with an exception handler defined for a multiple exceptions in a list
1393
+ app = ApiGatewayResolver ()
1394
+ event = deepcopy (LOAD_GW_EVENT )
1395
+
1396
+ @app .exception_handler ([ValueError , NotFoundError ])
1397
+ def multiple_error (ex : Exception ):
1398
+ raise BadRequestError ("Bad request" )
1399
+
1400
+ @app .get ("/path/a" )
1401
+ def path_a () -> Response :
1402
+ raise ValueError ("foo" )
1403
+
1404
+ @app .get ("/path/b" )
1405
+ def path_b () -> Response :
1406
+ raise NotFoundError
1407
+
1408
+ # WHEN calling the app generating each exception
1409
+ for route in ["/path/a" , "/path/b" ]:
1410
+ event ["path" ] = route
1411
+ result = app (event , {})
1412
+
1413
+ # THEN call the exception handler in the same way for both exceptions
1414
+ assert result ["statusCode" ] == 400
1415
+ assert result ["multiValueHeaders" ]["Content-Type" ] == [content_types .APPLICATION_JSON ]
1416
+ expected = {"statusCode" : 400 , "message" : "Bad request" }
1417
+ assert result ["body" ] == json_dump (expected )
1418
+
1419
+
1420
+ def test_exception_handler_supports_multiple_decorators (json_dump ):
1421
+ # GIVEN a resolver with an exception handler defined with multiple decorators
1422
+ app = ApiGatewayResolver ()
1423
+ event = deepcopy (LOAD_GW_EVENT )
1424
+
1425
+ @app .exception_handler (ValueError )
1426
+ @app .exception_handler (NotFoundError )
1427
+ def multiple_error (ex : Exception ):
1428
+ raise BadRequestError ("Bad request" )
1429
+
1430
+ @app .get ("/path/a" )
1431
+ def path_a () -> Response :
1432
+ raise ValueError ("foo" )
1433
+
1434
+ @app .get ("/path/b" )
1435
+ def path_b () -> Response :
1436
+ raise NotFoundError
1437
+
1438
+ # WHEN calling the app generating each exception
1439
+ for route in ["/path/a" , "/path/b" ]:
1440
+ event ["path" ] = route
1441
+ result = app (event , {})
1442
+
1443
+ # THEN call the exception handler in the same way for both exceptions
1444
+ assert result ["statusCode" ] == 400
1445
+ assert result ["multiValueHeaders" ]["Content-Type" ] == [content_types .APPLICATION_JSON ]
1446
+ expected = {"statusCode" : 400 , "message" : "Bad request" }
1447
+ assert result ["body" ] == json_dump (expected )
1448
+
1449
+
1391
1450
def test_event_source_compatibility ():
1392
1451
# GIVEN
1393
1452
app = APIGatewayHttpResolver ()
0 commit comments