If route specified in replace_route() doesn't exist then return suitable error response
This commit is contained in:
parent
1c8d1aec2e
commit
0fb3e59e0d
@ -444,6 +444,14 @@ class InvalidParameterValueErrorTagSpotFleetRequest(EC2ClientError):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidParameterValueErrorReplaceRoute(EC2ClientError):
|
||||||
|
def __init__(self, cidr: str):
|
||||||
|
super().__init__(
|
||||||
|
"InvalidParameterValue",
|
||||||
|
f"There is no route defined for '{cidr}' in the route table. Use CreateRoute instead.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EmptyTagSpecError(EC2ClientError):
|
class EmptyTagSpecError(EC2ClientError):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__(
|
super().__init__(
|
||||||
|
@ -18,6 +18,7 @@ from ..exceptions import (
|
|||||||
InvalidRouteTableIdError,
|
InvalidRouteTableIdError,
|
||||||
InvalidAssociationIdError,
|
InvalidAssociationIdError,
|
||||||
InvalidDestinationCIDRBlockParameterError,
|
InvalidDestinationCIDRBlockParameterError,
|
||||||
|
InvalidParameterValueErrorReplaceRoute,
|
||||||
RouteAlreadyExistsError,
|
RouteAlreadyExistsError,
|
||||||
RouteNotSupportedError,
|
RouteNotSupportedError,
|
||||||
)
|
)
|
||||||
@ -451,7 +452,18 @@ class RouteBackend:
|
|||||||
route_id = generate_route_id(
|
route_id = generate_route_id(
|
||||||
route_table.id, destination_cidr_block, destination_ipv6_cidr_block
|
route_table.id, destination_cidr_block, destination_ipv6_cidr_block
|
||||||
)
|
)
|
||||||
route = route_table.routes[route_id]
|
try:
|
||||||
|
route = route_table.routes[route_id]
|
||||||
|
except KeyError:
|
||||||
|
cidr = (
|
||||||
|
destination_cidr_block
|
||||||
|
if destination_cidr_block
|
||||||
|
else destination_ipv6_cidr_block
|
||||||
|
)
|
||||||
|
# This should be 'raise InvalidRouteError(route_table_id, cidr)' in
|
||||||
|
# line with the delete_route() equivalent, but for some reason AWS
|
||||||
|
# returns InvalidParameterValue instead in this case.
|
||||||
|
raise InvalidParameterValueErrorReplaceRoute(cidr) from None
|
||||||
|
|
||||||
route.gateway = None
|
route.gateway = None
|
||||||
route.nat_gateway = None
|
route.nat_gateway = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user