Giter VIP home page Giter VIP logo

Comments (7)

ryanbrainard avatar ryanbrainard commented on May 21, 2024

Definitely sounds like a bug. The presence of a body should not affect the the post-processing. However I tried a quick unit test, but could not reproduce. Perhaps I'm missing something, but in the meantime, could you see if catch/andCatch work? If they do, is there an error returned?

from react-refetch.

neezer avatar neezer commented on May 21, 2024

@ryanbrainard catch/andCatch fails with

SyntaxError: Unexpected end of input

With no stacktrace.

from react-refetch.

ryanbrainard avatar ryanbrainard commented on May 21, 2024

@neezer Ok, so probably a problem with the JSON parser blowing up and rejecting the promise. What version of whatwg-fetch are you using? Either way, we can handle it in RR, but it wondering why my unit test didn't fail...

from react-refetch.

neezer avatar neezer commented on May 21, 2024

"whatwg-fetch": "^0.11.0"

from react-refetch.

ryanbrainard avatar ryanbrainard commented on May 21, 2024

Hmm, same as me. I can dig in more later. Guessing the problem is in https://github.com/heroku/react-refetch/blob/master/src/components/connect.js#L105-L112 if someone wants to experiment

from react-refetch.

neezer avatar neezer commented on May 21, 2024

@ryanbrainard That seems like a good guess. Thinking that because response.body stream is empty, the line that reads response.json() is effectively doing something akin to JSON.parse(""), which yields the same error I'm getting.

from react-refetch.

neezer avatar neezer commented on May 21, 2024

@ryanbrainard Toying around, this fixes the issue for me, though no vote on whether or not this is a good approach (just adding an early return):

function handleResponse(response) {
  if (response.headers.get('content-type') === null)  return;

  var json = response.json(); // TODO: support other response types
  if (response.status >= 200 && response.status < 300) {
    // TODO: support custom acceptable statuses
    return json;
  } else {
    return json.then(function (cause) {
      return Promise.reject((0, _errors2.default)(cause));
    });
  }
}

Perhaps better to gate the JSON parsing based on whether or not the Content-Type is actually application/json.

from react-refetch.

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.