Skip to content

Commit

Permalink
Make request_id a string instead of tuple (beam-community#763)
Browse files Browse the repository at this point in the history
The request_id in Stripe.Error was being set to a tuple that
represented the "Request-Id" header. Now it will instead be a String
like described in the typespec.
  • Loading branch information
mattnenterprise authored and nkezhaya committed Feb 17, 2023
1 parent bbc139d commit e884ce1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/stripe/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@ defmodule Stripe.API do
end

defp handle_response({:ok, status, headers, body}) when status >= 300 and status <= 599 do
request_id = headers |> List.keyfind("Request-Id", 0)
request_id =
Enum.find_value(headers, fn
{"Request-Id", request_id} -> request_id
_header -> nil
end)

error =
case json_library().decode(body) do
Expand Down
4 changes: 4 additions & 0 deletions test/stripe/api_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ defmodule Stripe.APITest do
Stripe.API.request(%{}, :get, "/", %{}, [])
end

test "request_id is a string" do
{:error, %Stripe.Error{request_id: "req_123"}} = Stripe.API.request(%{}, :get, "/", %{}, [])
end

test "oauth_request works" do
verify_on_exit!()

Expand Down

0 comments on commit e884ce1

Please sign in to comment.