Giter Site home page Giter Site logo

JSON response causes error about httpoison HOT 7 CLOSED

edgurgel avatar edgurgel commented on May 3, 2024
JSON response causes error

from httpoison.

Comments (7)

edgurgel avatar edgurgel commented on May 3, 2024

Can you share the last line executed on HTTPoison code? Also which version are you using?

from httpoison.

BlakeWilliams avatar BlakeWilliams commented on May 3, 2024

Sure thing!

I'm using 0.4 and I'm calling HTTPoison.get("http://endpoint.herokuapp.com/long/api/path", headers)

Turns out the request succeeds locally where I don't have much data, but it seems to fail when I hit the remote endpoint which has a bit larger amount. It's nothing ridiculous though.

Sorry for the poor error report, it's late and I didn't know if this would actually get addressed any time soon.

Hackney gave :closed and the response back, I got this from removing the raise on body issues.

from httpoison.

BlakeWilliams avatar BlakeWilliams commented on May 3, 2024

So the issue might just be that HTTPoison only responds with the body only on {:ok, body} and not {:closed, body} as well?

from httpoison.

edgurgel avatar edgurgel commented on May 3, 2024

Found the issue:

HTTPoison is calling to_string on this tuple. I think the right thing is to pass the reason as it's.

Adding this test on httpoison_base_test.exs shows the issue:

  test "request failing with a error reason tuple" do
    expect(:hackney, :request, 5, {:error, {:closed, "Something happened"}})

    assert_raise HTTPoison.HTTPError, "...", fn ->
      HTTPoison.post("localhost", "body")
    end

    assert validate :hackney
  end

Speaking of this, I'm also considering (as a breaking change) to not raise errors, just return a HTTPError struct. It would have a better behaviour and perfect for just pattern matching. I'll open an issue as "discussion".

Edited to add the place where we call to_string: https://github.com/edgurgel/httpoison/blob/master/lib/httpoison/base.ex#L93-L94

from httpoison.

BlakeWilliams avatar BlakeWilliams commented on May 3, 2024

Sounds good, I think that's a much better way to approach the issue and was considering bringing it up.

from httpoison.

edgurgel avatar edgurgel commented on May 3, 2024

Released a new version with this fix: https://github.com/edgurgel/httpoison/releases/tag/0.4.3 , https://hex.pm/packages/httpoison/0.4.3

0.5.* may not have exceptions anymore.

from httpoison.

BlakeWilliams avatar BlakeWilliams commented on May 3, 2024

Thanks!

from httpoison.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.