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

api_common.js 中偶尔会出现的一个错误 #44

Open
finscn opened this issue Jun 4, 2015 · 0 comments
Open

api_common.js 中偶尔会出现的一个错误 #44

finscn opened this issue Jun 4, 2015 · 0 comments

Comments

@finscn
Copy link

finscn commented Jun 4, 2015

我这边的版本 (可能和github上的有差异) , 该文件第 161 行 有时候会报错.
错误的原因是, data 为空

API.prototype.getAccessToken = function (callback) {
  var that = this;
  var url = this.prefix + 'token?grant_type=client_credential&appid=' + this.appid + '&secret=' + this.appsecret;
  this.request(url, {dataType: 'json'}, wrapper(function (err, data) {
    if (err) {
      return callback(err);
    }
    // 过期时间,因网络延迟等,将实际过期时间提前10秒,以防止临界点

// *************************** 这里就是  161 行 *************************** //
    var expireTime = (new Date().getTime()) + (data.expires_in - 10) * 1000;
// ************************************************************************** //

    var token = AccessToken(data.access_token, expireTime);
    that.saveToken(token, function (err) {
      if (err) {
        return callback(err);
      }
      callback(err, token);
    });
  }));
  return this;
};

建议此处 data如果为空 当做错误处理.
或者是在外层的某个地方生成 err .

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