Closed ggiill closed 1 year ago
This just started happening today:
{:error, {Tesla.Middleware.JSON, :decode, %Jason.DecodeError{ data: <<...REDACTED...>>, position: 0, token: nil }}}
Dug in a bit, and the order of the Tesla.Middleware makes a difference here for some reason.
These don't work:
ExForce.OAuth.get_token( instance_url, grant_type: "refresh_token", client_id: client_id, client_secret: client_secret, refresh_token: refresh_token )
instance_url |> ExForce.Client.build_oauth_client() |> Tesla.post( instance_url <> "/services/oauth2/token", %{ grant_type: "refresh_token", client_id: client_id, client_secret: client_secret, refresh_token: refresh_token } )
[ {Tesla.Middleware.BaseUrl, instance_url}, {Tesla.Middleware.Compression, format: "gzip"}, Tesla.Middleware.FormUrlencoded, {Tesla.Middleware.DecodeJson, engine: Jason}, {Tesla.Middleware.Headers, []} ] |> Tesla.client() |> Tesla.post( "/services/oauth2/token", %{ grant_type: "refresh_token", client_id: client_id, client_secret: client_secret, refresh_token: refresh_token } )
(This one ^^^ is basically ExForce.Client.Tesla.build_oauth_client/2)
ExForce.Client.Tesla.build_oauth_client/2
But moving Tesla.Middleware.DecodeJson first in the list of middleware does, and yields an {:ok, %Tesla.Env{}} tuple with decoded JSON body:
Tesla.Middleware.DecodeJson
{:ok, %Tesla.Env{}}
body
[ {Tesla.Middleware.DecodeJson, engine: Jason}, {Tesla.Middleware.BaseUrl, instance_url}, {Tesla.Middleware.Compression, format: "gzip"}, Tesla.Middleware.FormUrlencoded, {Tesla.Middleware.Headers, []} ] |> Tesla.client() |> Tesla.post( "/services/oauth2/token", %{ grant_type: "refresh_token", client_id: client_id, client_secret: client_secret, refresh_token: refresh_token } )
Update: This seems to actually be an issue with bumping tesla from 1.4.4 to 1.5.1...
tesla
1.4.4
1.5.1
...though this could be fixed by switching the order of the middleware: https://github.com/chulkilee/ex_force/pull/42
This just started happening today:
Dug in a bit, and the order of the Tesla.Middleware makes a difference here for some reason.
These don't work:
(This one ^^^ is basically
ExForce.Client.Tesla.build_oauth_client/2
)But moving
Tesla.Middleware.DecodeJson
first in the list of middleware does, and yields an{:ok, %Tesla.Env{}}
tuple with decoded JSONbody
: