Git Product home page Git Product logo

Comments (6)

BenPatterson2 avatar BenPatterson2 commented on June 2, 2024

I think this could be fixed if AbortController (abort-controller) is used instead of Promise.race, the fetch library would have to be switched to node-fetch do that since I don't think the current fetch library supports it.

const controller = new AbortController();
const signal = controller.signal;
const options = {
   signal,
   method,
   headers: {
     ...fetchHeaders,
     ...headers,
   },
 };
 let timedOut = false;
 const timeout = setTimeout(() => {
     timedOut = true;
     controller.abort();
  },12000)
return fetch(url, options)
   .catch(err => {
    clearTimeout(timeout);
     if (timedOut) {
       throw Object.assign(new Error(`Request: ${fetchUrl} timed out after ${timeout} milliseconds`), { type: 'timeout' });
     }
     throw err;
   });

from avatax-rest-v2-js-sdk.

michaelsinghurse avatar michaelsinghurse commented on June 2, 2024

Ben, could you do something like this, which doesn't require any additional dependencies? It's not too elegant but might get the job done.

function withTimeout(msecs, promise) {
  return new Promise((resolve, reject) => {
    let timeoutId = setTimeout(() => {
      reject(new Error('timeout'));
    }, msecs);

    promise
      .then(result => {
        clearTimeout(timeoutId);
        resolve(result);
      })
      .catch(error => {
        reject(error);
      });
  });
}

from avatax-rest-v2-js-sdk.

BenPatterson2 avatar BenPatterson2 commented on June 2, 2024

Oh, yes. I misread the original issue and missed that you were getting a resolution of the tax rates object.

Think my example is fixing a bug you're not experiencing.

from avatax-rest-v2-js-sdk.

michaelsinghurse avatar michaelsinghurse commented on June 2, 2024

Sounds good, Ben. One modification to what I proposed above. I think you'd want to clear the timeout whether the promise resolves or rejects, and so it could go in the finally method.

function withTimeout(msecs, promise) {
  return new Promise((resolve, reject) => {
    let timeoutId = setTimeout(() => {
      reject(new Error('timeout'));
    }, msecs);

    promise
      .then(result => {
        resolve(result);
      })
      .catch(error => {
        reject(error);
      })
      .finally(() => {
        clearTimeout(timeoutId);
      });
  });
}

from avatax-rest-v2-js-sdk.

vitali-ausianik avatar vitali-ausianik commented on June 2, 2024

Any updates here? I still use version 20.6.0 and cannot update it because of this core issue.

from avatax-rest-v2-js-sdk.

svc-developer avatar svc-developer commented on June 2, 2024

This has been resolved. Please upgrade to the latest version of SDK.
Thanks

from avatax-rest-v2-js-sdk.

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.