Skip to content

Commit 7e92bcf

Browse files
authored
Fix failures in IAM tests (#691)
The test is expecting an `AWSException` with code `"InvalidAction"` but the caught exception had code 404. It appears to be because the response body is XML but AWS didn't set the `Content-Type` header nor did it begin the response body with a clear indicator of the content type, so the body doesn't get properly parsed. To fix this, we can expand the set of things we look for to determine when to parse as XML. Previously we were only looking for `/xml` at the end of the content or `<?xml` at the beginning of the body, but the error response has neither, so here I've added a check for `<\w+ xmlns=` at the beginning of the body. This seems to be the expected format of an XML response when the `<?xml` line is absent. Documentation suggests that `<?xml` would only be absent in the case of an `ErrorResponse` but that the `Content-Type` header would be set to `text/xml`. Evidently not true in practice...
1 parent 51b3b0d commit 7e92bcf

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/AWSExceptions.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ function AWSException(e::HTTP.StatusError, body::AbstractString)
9898
end
9999

100100
# Extract API error code from XML error message...
101-
if endswith(content_type, "/xml") || startswith(body, "<?xml")
101+
if (
102+
endswith(content_type, "/xml") ||
103+
startswith(body, "<?xml") ||
104+
startswith(body, r"<\w+ xmlns=")
105+
)
102106
info = parse_xml(body)
103107
end
104108
elseif parse(Int, HTTP.header(e.response, "Content-Length", "0")) > 0

0 commit comments

Comments
 (0)