From b66272717fa0aa46c3e1bf7894e9c719f8388ed3 Mon Sep 17 00:00:00 2001 From: Viren Nadkarni Date: Tue, 4 Jul 2023 16:36:20 +0530 Subject: [PATCH] Add type:Sender field to error response (#6465) --- moto/core/exceptions.py | 10 ++++++++-- moto/sns/exceptions.py | 1 + tests/test_sns/test_topics_boto3.py | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/moto/core/exceptions.py b/moto/core/exceptions.py index 5c0e306c2..51f219e1e 100644 --- a/moto/core/exceptions.py +++ b/moto/core/exceptions.py @@ -3,8 +3,6 @@ from jinja2 import DictLoader, Environment from typing import Any, List, Tuple, Optional import json -# TODO: add "Sender" to error responses below? - SINGLE_ERROR_RESPONSE = """ @@ -20,6 +18,9 @@ WRAPPED_SINGLE_ERROR_RESPONSE = """ {{error_type}} + {% if include_type_sender %} + Sender + {% endif %} {% block extra %}{% endblock %} <{{request_id_tag}}>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE @@ -44,6 +45,10 @@ class RESTError(HTTPException): # most APIs use , but some APIs (including EC2, S3) use request_id_tag_name = "RequestId" + # When this field is set, the `Type` field will be included in the response + # This indicates that the fault lies with the client + include_type_sender = True + templates = { "single_error": SINGLE_ERROR_RESPONSE, "wrapped_single_error": WRAPPED_SINGLE_ERROR_RESPONSE, @@ -63,6 +68,7 @@ class RESTError(HTTPException): error_type=error_type, message=message, request_id_tag=self.request_id_tag_name, + include_type_sender=self.include_type_sender, **kwargs, ) self.content_type = "application/xml" diff --git a/moto/sns/exceptions.py b/moto/sns/exceptions.py index 705d5539f..b1704e303 100644 --- a/moto/sns/exceptions.py +++ b/moto/sns/exceptions.py @@ -67,6 +67,7 @@ class TagLimitExceededError(SNSException): class InternalError(SNSException): code = 500 + include_type_sender = False def __init__(self, message: str): super().__init__("InternalFailure", message) diff --git a/tests/test_sns/test_topics_boto3.py b/tests/test_sns/test_topics_boto3.py index 964b724fc..cb99afb4a 100644 --- a/tests/test_sns/test_topics_boto3.py +++ b/tests/test_sns/test_topics_boto3.py @@ -148,6 +148,7 @@ def test_create_topic_in_multiple_regions(): err = exc.value.response["Error"] assert err["Code"] == "NotFound" assert err["Message"] == "Topic does not exist" + assert err["Type"] == "Sender" @mock_sns @@ -538,6 +539,7 @@ def test_create_fifo_topic(): "Fifo Topic names must end with .fifo and must be made up of only uppercase and lowercase ASCII letters, " "numbers, underscores, and hyphens, and must be between 1 and 256 characters long." ) + err.response["Error"]["Type"].should.equal("Sender") try: conn.create_topic(Name="test_topic.fifo")