code: function retry(options, defer, times) {
    // bind the defer object to cb
    request(options, function(err, res, body) {
      if (!err && res) {
        if (res.statusCode == 200) {
          defer.resolve(body);
        } else {
          defer.reject(res.statusCode)
        }
      } else {
        console.log(err);
        if (times--) retry(options, defer, times);
        // if err, reject
        else defer.reject(err);
      }
    });
  }
docs: the recursive retry request() function callback for request JS the recursive retry request() function