peburrows / goth

Elixir package for Oauth authentication via Google Cloud APIs
http://hexdocs.pm/goth
MIT License
284 stars 108 forks source link

Add pattern matching when body is already a map #132

Closed aleDsz closed 2 years ago

aleDsz commented 2 years ago

I've found this when trying to use the http_client: &Req.request/1 option, because the body was already decoded by Req


  * 1st argument: not an iodata term

    :erlang.iolist_to_binary(%{"access_token" => "...", "expires_in" => 3599, "token_type" => "Bearer"})
    (jason 1.3.0) lib/jason.ex:69: Jason.decode/2
    (goth 1.3.0-rc.4) lib/goth/token.ex:277: Goth.Token.handle_response/1
    (goth 1.3.0-rc.4) lib/goth/token.ex:213: Goth.Token.request/1
    (goth 1.3.0-rc.4) lib/goth.ex:213: Goth.prefetch/1
    (goth 1.3.0-rc.4) lib/goth.ex:206: Goth.handle_continue/2
    (stdlib 3.17) gen_server.erl:695: :gen_server.try_dispatch/4
    (stdlib 3.17) gen_server.erl:437: :gen_server.loop/7
Last message: {:continue, :async_prefetch}

With this PR, it solves the bug and we can use a HTTP Client that returns a decoded body

wojtekmach commented 2 years ago

Nice catch, thanks!