Error handling: Model-level validations, proper error responses.
This commit is contained in:
parent
b94401247f
commit
071c03e216
25 changed files with 616 additions and 287 deletions
|
|
@ -4,18 +4,13 @@ from moto.core.responses import BaseResponse
|
|||
from moto.core.utils import camelcase_to_underscores
|
||||
from moto.ec2.models import ec2_backend
|
||||
from moto.ec2.utils import instance_ids_from_querystring, filters_from_querystring, filter_reservations
|
||||
from moto.ec2.exceptions import InvalidIdError
|
||||
|
||||
|
||||
class InstanceResponse(BaseResponse):
|
||||
def describe_instances(self):
|
||||
instance_ids = instance_ids_from_querystring(self.querystring)
|
||||
if instance_ids:
|
||||
try:
|
||||
reservations = ec2_backend.get_reservations_by_instance_ids(instance_ids)
|
||||
except InvalidIdError as exc:
|
||||
template = Template(EC2_INVALID_INSTANCE_ID)
|
||||
return template.render(instance_id=exc.id), dict(status=400)
|
||||
reservations = ec2_backend.get_reservations_by_instance_ids(instance_ids)
|
||||
else:
|
||||
reservations = ec2_backend.all_reservations(make_copy=True)
|
||||
|
||||
|
|
@ -353,9 +348,3 @@ EC2_MODIFY_INSTANCE_ATTRIBUTE = """<ModifyInstanceAttributeResponse xmlns="http:
|
|||
<return>true</return>
|
||||
</ModifyInstanceAttributeResponse>"""
|
||||
|
||||
|
||||
EC2_INVALID_INSTANCE_ID = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Response><Errors><Error><Code>InvalidInstanceID.NotFound</Code>
|
||||
<Message>The instance ID '{{ instance_id }}' does not exist</Message></Error>
|
||||
</Errors>
|
||||
<RequestID>39070fe4-6f6d-4565-aecd-7850607e4555</RequestID></Response>"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue