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)
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, 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
}
)
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.DecodeJsonfirst in the list of middleware does, and yields an{:ok, %Tesla.Env{}}tuple with decoded JSONbody: