Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad1350f

Browse files
authored
fix service name and NS URLs for XML service responses (#3127)
1 parent 837ffd2 commit ad1350f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

‎localstack/utils/aws/aws_responses.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ def requests_error_response_json(msg, code=500, error_type='InternalFailure'):
3737
return flask_to_requests_response(response)
3838

3939

40-
def requests_error_response_xml(service, message, code=400, code_string='InvalidParameter'):
40+
def requests_error_response_xml(message, code=400, code_string='InvalidParameter', service=None, xmlns=None):
4141
response = RequestsResponse()
42-
response._content = """<ErrorResponse xmlns="http://{service}.amazonaws.com/doc/2010-03-31/"><Error>
42+
xmlns = xmlns or 'http://%s.amazonaws.com/doc/2010-03-31/' % service
43+
response._content = """<ErrorResponse xmlns="{xmlns}"><Error>
4344
<Type>Sender</Type>
4445
<Code>{code_string}</Code>
4546
<Message>{message}</Message>
4647
</Error><RequestId>{req_id}</RequestId>
47-
</ErrorResponse>""".format(service=service, message=message, code_string=code_string, req_id=short_uid())
48+
</ErrorResponse>""".format(xmlns=xmlns, message=message, code_string=code_string, req_id=short_uid())
4849
response.status_code = code
4950
return response
5051

@@ -93,18 +94,18 @@ def requests_error_response_xml_signature_calculation(message, string_to_sign=No
9394
return response
9495

9596

96-
def flask_error_response_xml(message, code=500, code_string='InternalFailure'):
97-
response = requests_error_response_xml(message, code=code, code_string=code_string)
97+
def flask_error_response_xml(message, code=500, code_string='InternalFailure', service=None, xmlns=None):
98+
response = requests_error_response_xml(message, code=code, code_string=code_string, service=service, xmlns=xmlns)
9899
return requests_to_flask_response(response)
99100

100101

101-
def requests_error_response(req_headers, message, code=500, error_type='InternalFailure'):
102+
def requests_error_response(req_headers, message, code=500, error_type='InternalFailure', service=None, xmlns=None):
102103
ctype = req_headers.get('Content-Type', '')
103104
accept = req_headers.get('Accept', '')
104105
is_json = 'json' in ctype or 'json' in accept
105106
if is_json:
106107
return requests_error_response_json(msg=message, code=code, error_type=error_type)
107-
return requests_error_response_xml(message, code=code, code_string=error_type)
108+
return requests_error_response_xml(message, code=code, code_string=error_type, service=service, xmlns=xmlns)
108109

109110

110111
def requests_response(content, status_code=200, headers={}):

0 commit comments

Comments
 (0)