Add type:Sender field to error response (#6465)
This commit is contained in:
parent
7f43889ef6
commit
b66272717f
@ -3,8 +3,6 @@ from jinja2 import DictLoader, Environment
|
||||
from typing import Any, List, Tuple, Optional
|
||||
import json
|
||||
|
||||
# TODO: add "<Type>Sender</Type>" to error responses below?
|
||||
|
||||
|
||||
SINGLE_ERROR_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Error>
|
||||
@ -20,6 +18,9 @@ WRAPPED_SINGLE_ERROR_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Error>
|
||||
<Code>{{error_type}}</Code>
|
||||
<Message><![CDATA[{{message}}]]></Message>
|
||||
{% if include_type_sender %}
|
||||
<Type>Sender</Type>
|
||||
{% endif %}
|
||||
{% block extra %}{% endblock %}
|
||||
<{{request_id_tag}}>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</{{request_id_tag}}>
|
||||
</Error>
|
||||
@ -44,6 +45,10 @@ class RESTError(HTTPException):
|
||||
# most APIs use <RequestId>, but some APIs (including EC2, S3) use <RequestID>
|
||||
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"
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user