Skip to content

Possible to backoff from inside function call? #29

@als9xd

Description

@als9xd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions