tesla icon indicating copy to clipboard operation
tesla copied to clipboard

Json decoding

Open MeerKatDev opened this issue 2 years ago • 4 comments

I'm having an issue with the json decoding, in the tests Tesla isn't giving back a json, but a string. This is the logging result:

<<< RESPONSE <<<
content-type: application/json

"
{:ok,
 %Tesla.Env{
   __client__: nil,
   __module__: nil,
   body: "{\n  \"success\": true,\n  \"listing\": {\n    \"ticketId\": 123,\n    \"productionId\": 123,\n    \"id\": 123\n  }\n}\n",
   headers: [{"content-type", "application/json"}],
   method: nil,
   opts: [],
   query: [],
   status: 200,
   url: ""
 }}

The request is a POST request with the following headers:

>>> REQUEST >>>
(no query)
api-token: ***
content-type: application/json

and this is how the client is built:

    headers = [{"api-token", "#{api_token}"}]

    Tesla.client([
      {Tesla.Middleware.BaseUrl, @base_url},
      {Tesla.Middleware.Retry, [
        delay: 500,
        max_retries: 2,
        max_delay: 10_000,
        should_retry: &some_fun/1]},
      {Tesla.Middleware.Headers, headers},
      Tesla.Middleware.JSON,
      Tesla.Middleware.Telemetry,
      Tesla.Middleware.KeepRequest,
      {Tesla.Middleware.Logger, account: account, additional_logs: additional_logs}
    ])

Jason is listed in the dependencies.

MeerKatDev avatar Mar 06 '22 11:03 MeerKatDev

Is this library still supported? I tried to clean and recompile tesla, but to no avail. Also, there isn't any indication in the compilation process telling me that it works.

MeerKatDev avatar Mar 17 '22 07:03 MeerKatDev

Also, when I put exactly {:jason, ">= 1.0"} in deps, mix gives an error

MeerKatDev avatar Mar 17 '22 07:03 MeerKatDev

Did you find a solution? I seem to have the same problem, and am unsure if I'm using it wrong.

Piping the response body into Jason.decode works fine.

Straffern avatar Apr 04 '22 19:04 Straffern

@MeerKatDev @Straffern Can you provide an executable example?

teamon avatar May 08 '22 07:05 teamon

Hey peeps, could you provide some example repo reproducing the bug?

yordis avatar Dec 28 '22 14:12 yordis

Sorry, only the code above. I don't have that codebase anymore.

MeerKatDev avatar Jan 03 '23 17:01 MeerKatDev

Hey there, I tried it, but I didn't get anywhere.

Please provide some complete example codes on how to reproduce the issue since it is really hard to asses fully what is going on.

Feel free to reopen the issue if the error persists.

yordis avatar Jan 04 '23 17:01 yordis