diff --git a/moto/sns/exceptions.py b/moto/sns/exceptions.py index 74d25608e..30995a318 100644 --- a/moto/sns/exceptions.py +++ b/moto/sns/exceptions.py @@ -1,23 +1,11 @@ from __future__ import unicode_literals from moto.core.exceptions import RESTError -NOT_FOUND_ENDPOINT_ERROR = """ - - {{ sender }} - {{ error_type }} - {{ message }} - - 9dd01905-5012-5f99-8663-4b3ecd0dfaef -""" - class SNSNotFoundError(RESTError): code = 404 def __init__(self, message, **kwargs): - kwargs.setdefault("template", "endpoint_error") - kwargs.setdefault("sender", "Sender") - self.templates["endpoint_error"] = NOT_FOUND_ENDPOINT_ERROR super(SNSNotFoundError, self).__init__("NotFound", message, **kwargs) diff --git a/moto/sns/responses.py b/moto/sns/responses.py index dd30d6517..f73c03827 100644 --- a/moto/sns/responses.py +++ b/moto/sns/responses.py @@ -6,7 +6,7 @@ from collections import defaultdict from moto.core.responses import BaseResponse from moto.core.utils import camelcase_to_underscores from .models import sns_backends -from .exceptions import InvalidParameterValue +from .exceptions import InvalidParameterValue, SNSNotFoundError from .utils import is_e164 @@ -543,24 +543,28 @@ class SNSResponse(BaseResponse): def get_endpoint_attributes(self): arn = self._get_param("EndpointArn") - endpoint = self.backend.get_endpoint(arn) + try: + endpoint = self.backend.get_endpoint(arn) - if self.request_json: - return json.dumps( - { - "GetEndpointAttributesResponse": { - "GetEndpointAttributesResult": { - "Attributes": endpoint.attributes - }, - "ResponseMetadata": { - "RequestId": "384ac68d-3775-11df-8963-01868b7c937f" - }, + if self.request_json: + return json.dumps( + { + "GetEndpointAttributesResponse": { + "GetEndpointAttributesResult": { + "Attributes": endpoint.attributes + }, + "ResponseMetadata": { + "RequestId": "384ac68d-3775-11df-8963-01868b7c937f" + }, + } } - } - ) + ) - template = self.response_template(GET_ENDPOINT_ATTRIBUTES_TEMPLATE) - return template.render(endpoint=endpoint) + template = self.response_template(GET_ENDPOINT_ATTRIBUTES_TEMPLATE) + return template.render(endpoint=endpoint) + except SNSNotFoundError: + error_response = self._error("NotFound", "Endpoint does not exist") + return error_response, dict(status=404) def set_endpoint_attributes(self): arn = self._get_param("EndpointArn")