Repository: getmoto/moto

Issue:
SNS Response Template Duplicate
The following response templates are essentially the same:

* [moto/sns/exceptions.py](https://github.com/spulec/moto/blob/master/moto/sns/exceptions.py#L4)
* [moto/sns/responses.p](https://github.com/spulec/moto/blob/master/moto/sns/responses.py#L1095)

The one in `exceptions.py` was added in e9dc5ed  to correct the response 
returned by get_endpoint_attributes for a non-existent endpoint. However,
after some more inspection, it was found that a valid template already existed
in `responses.py`

The template from `exceptions.py` could be removed after all, since it is the
one added later, and the one from `responses.py` could be used for the same
purpose


Discussion:

Resolving patch:
diff --git a/moto/sns/exceptions.py b/moto/sns/exceptions.py
--- 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 = """<ErrorResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
-  <Error>
-    <Type>{{ sender }}</Type>
-    <Code>{{ error_type }}</Code>
-    <Message>{{ message }}</Message>
-  </Error>
-  <RequestId>9dd01905-5012-5f99-8663-4b3ecd0dfaef</RequestId>
-</ErrorResponse>"""
-
 
 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
--- a/moto/sns/responses.py
+++ b/moto/sns/responses.py
@@ -6,7 +6,7 @@
 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 @@ def list_endpoints_by_platform_application(self):
 
     def get_endpoint_attributes(self):
         arn = self._get_param("EndpointArn")
-        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"
-                        },
+        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"
+                            },
+                        }
                     }
-                }
-            )
+                )
 
-        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")


Test patch: