Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to backoff from inside function call? #29

Open
als9xd opened this issue Sep 17, 2018 · 0 comments
Open

Possible to backoff from inside function call? #29

als9xd opened this issue Sep 17, 2018 · 0 comments

Comments

@als9xd
Copy link

als9xd commented Sep 17, 2018

I'm working with an api where sometimes the res.statusCode for a request is 503 but the err.code isn't. This means call.retryIf is never called because err is undefined.

My attempted remedy:

const reqRetryCodes = {
    'ECONNRESET': true,
    'ETIMEDOUT': true,
    'ENOTFOUND': true,
    503: true
}

        const _tryRequest = backoff.call(
            request,
            {
                url: myUrl,
                json: true
            },
            (err,res,body) => {
                if(err){
                    if(reqRetryCodes[err.code]===true){
                        _tryRequest.backoff(); //retry backoff
                        return;
                    }
                    reject(err);
                    return;
                }
                if(reqRetryCodes[res.statusCode]===true){
                    _tryRequest.backoff(); //retry backoff
                    return;
                }
                resolve(body);
            }
        );

        _tryRequest.setStrategy(new backoff.ExponentialStrategy());
        _tryRequest.start();

Gives:

TypeError: _tryRequest.backoff is not a function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant