diff --git a/Project.toml b/Project.toml index 1da3c51b77..efe0825efc 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "AWS" uuid = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc" license = "MIT" -version = "1.84.0" +version = "1.84.1" [deps] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" diff --git a/src/AWSExceptions.jl b/src/AWSExceptions.jl index 092a2dafc9..f21631879e 100644 --- a/src/AWSExceptions.jl +++ b/src/AWSExceptions.jl @@ -109,15 +109,18 @@ function AWSException(e::HTTP.StatusError, body::AbstractString) end end - # There are times when Errors or Error are returned back - info = get(info, "Errors", info) - info = get(info, "Error", info) + # Sometimes info is a string, in which case there is nothing else to do + if info isa AbstractDict + # There are times when Errors or Error are returned back + info = get(info, "Errors", info) + info = get(info, "Error", info) - code = get(info, "Code", code) + code = get(info, "Code", code) - # There are also times when the response back is (M|m)essage - message = get(info, "Message", message) - message = get(info, "message", message) + # There are also times when the response back is (M|m)essage + message = get(info, "Message", message) + message = get(info, "message", message) + end streamed_body = !HTTP.isbytes(e.response.body) ? body : nothing diff --git a/test/AWSExceptions.jl b/test/AWSExceptions.jl index 2ad9c8c25a..52fa62ac3a 100644 --- a/test/AWSExceptions.jl +++ b/test/AWSExceptions.jl @@ -93,4 +93,32 @@ _test_exception(ex, expected, "$msg") @test ex.info["__type"] == expected["code"] end + + @testset "JSON requests can have invalid bodies" begin + expected = Dict( + "code" => "400", + "message" => "AWSException", + "headers" => ["Content-Type" => "application/json"], + "status_code" => 400, + ) + + expected["body"] = IOBuffer() + expected["streamed_body"] = "\"foo\"" + + # This does not actually send a request, just creates the object to test with + req = HTTP.Request("GET", "https://aws.com", expected["headers"], expected["body"]) + resp = HTTP.Response( + expected["status_code"], expected["headers"]; body=expected["body"], request=req + ) + status_error = AWS.statuserror(expected["status_code"], resp) + ex = AWSException(status_error, expected["streamed_body"]) + + @test ex.code == expected["code"] + @test ex.info == "foo" # nothing better we can do than just forward the invalid body + @test ex.message == expected["message"] + @test ex.cause.response.body == expected["body"] + @test ex.cause.status == expected["status_code"] + @test ex.cause.response.headers == expected["headers"] + @test ex.streamed_body == expected["streamed_body"] + end end