ex-aws / ex_aws

A flexible, easy to use set of clients AWS APIs for Elixir

Home Page:https://hex.pm/packages/ex_aws

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

301 errors do not include the http response, unlike other errors

robpallotta opened this issue · comments

301 redirect errors do not include the raw http response the same way that other errors do. This prevents users from appropriately handling certain error cases, such as s3 redirects. The returned value should be consistent across all error types.

Environment

  • Elixir & Erlang versions (elixir --version):

Erlang/OTP 25 [erts-13.2.2.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit:ns]

Elixir 1.14.5 (compiled with Erlang/OTP 25)

  • ExAws version mix deps |grep ex_aws

ex_aws 2.5.1
ex_aws_s3 2.5.3

  • HTTP client version. IE for hackney do mix deps | grep hackney

hackney 1.20.1

Current behavior

301 redirect error is missing http response details, other error includes http response details:

ExAws.S3.get_object("bucket-in-another-region", "non-existent-file") |> ExAws.request
[warning] ExAws: Received redirect, did you specify the correct region?
{:error, {:http_error, 301, "redirected"}}

ExAws.S3.get_object("bucket-in-same-region", "non-existent-file") |> ExAws.request()
{:error,
 {:http_error, 404,
  %{
    body: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>NoSuchKey</Code><Message>The specified key does not exis$
    headers: [
      {"x-amz-request-id", "9Z70W9SJR886K7BY"},
      {"x-amz-id-2",
       "wZiIt5U9qQr3zZaM0J2c5eM9VKVXdA6ABqkFpma77/BPz999LpWXNVswJAqYcKTBt7QhsR22NKY="},
      {"Content-Type", "application/xml"},
      {"Transfer-Encoding", "chunked"},
      {"Date", "Tue, 13 Feb 2024 01:22:33 GMT"},
      {"Server", "AmazonS3"}
    ],
    status_code: 404
  }}}

Expected behavior

301 redirect error should include http response in the same way as the other error:

ExAws.S3.get_object("bucket-in-another-region", "non-existent-file") |> ExAws.request
[warning] ExAws: Received redirect, did you specify the correct region?
{:error,
 {:http_error, 301,
  %{
    body: ...ommitted...,
    headers: [
      {"x-amz-bucket-region", "us-east-1"},
      {"x-amz-request-id", "ZQN1XPKDKPKSJ887"},
      {"x-amz-id-2",
       "zZtkGSy3AxBOPv7JQPl7D9Q1CtQsdWsLUPGWtwPO4Ei7Brp1MDhsZbNTUEUi7yv7mKEpX/zC7TM="},
      {"Content-Type", "application/xml"},
      {"Transfer-Encoding", "chunked"},
      {"Date", "Mon, 12 Feb 2024 02:54:23 GMT"},
      {"Server", "AmazonS3"}
    ],
    status_code: 301
  }
 }
}