Giter Site home page Giter Site logo

Comments (3)

mdlavin avatar mdlavin commented on May 28, 2024

I've never seen axios-auth-refresh before. Seems like a very practical helper library. I'm not sure about why it wouldn't work, but I'd be happy to review a PR if you have an environment to reproduce and debug the problem.

from axios-fetch.

SimeonC avatar SimeonC commented on May 28, 2024

We had the same issue and I eventually tracked it down to this here;

validateStatus: () => true

This line basically stops axios from entering the "error" side of the interceptors chain.

What it should be is this; https://github.com/axios/axios/blob/c7329fefc890050edd51e40e469a154d0117fc55/lib/defaults.js#L79-L81

Which would correctly enter the "error" side of the response interceptor.

I think the reason this line was added was due to the usage of await rather than promises?

from axios-fetch.

hogpilot avatar hogpilot commented on May 28, 2024

I ran into this same issue and agree with @SimeonC that validateStatus: () => true is the culprit. I think the reason it was there is because of the way the Fetch API is implemented:

The Promise returned from fetch() won’t reject on HTTP error status even if the response is an HTTP 404 or 500. Instead, it will resolve normally (with ok status set to false), and it will only reject on network failure or if anything prevented the request from completing.

I think a fix would be to remove the custom validateStatus (and thus default to the one referenced by @SimeonC), and wrap the request in a try...catch instead:

axios-fetch/src/index.js [starting at line 21]

 const config = transfomer({
    url: input,
    method: init.method || 'GET',
    data: init.body instanceof FormData ? init.body : String(init.body),
    headers: lowerCasedHeaders,
    // validateStatus: () => true
  }, input, init);

  // const result = await axios.request(config);
  let result;
  try {
    result = await axios.request(config);
  } catch (err) {
    result = err.response;
  }

I'll submit a PR with this change for review.

from axios-fetch.

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.