首页 > 解决方案 > 即使生成了 GitHub 安装访问令牌,回调也会失败

问题描述

我有此代码用于生成安装访问令牌:

gitInstallationAccessToken.getAccessTokensUrl(jwt, function(appAccessTokensUrl) {

  var instance = axios({
    method: "POST",
    url: appAccessTokensUrl,
    headers: {
      "Accept" : "application/vnd.github.machine-man-preview+json",
      "Authorization" : `Bearer ${jwt}`
    }
  })
  .then(function(response) {
    var installationAccessToken = response.data.token;
    console.log(`Installation Access Token: ${installationAccessToken}`)
    callback(installationAccessToken);
  })
  .catch(function(error) {
    console.warn("Unable to authenticate");
    // The request was made and the server responded with a status code
    // that falls out of the range of 2xx
    if (error.response) {
      console.warn(`Status ${error.response.status}`);
      console.warn(`${error.response.data.message}`);
    }
  });
});

它输出Unable to authenticate所以在某些时候失败。我的问题是console.log('Installation Access Token: ${installationAccessToken}')输出一个令牌,所以我希望回调成功。有什么理由可能会失败吗?

附加信息

这是 catch 中返回的实际错误:

ReferenceError: regeneratorRuntime is not defined
    at eval (webpack:///./lib/githubService.js?:17:51)
    at Object.retrieveIssues (webpack:///./lib/githubService.js?:87:6)
    at eval (webpack:///./lib/getPublicGitHubIssues.js?:78:20)
    at eval (webpack:///./lib/gitInstallationAccessToken.js?:84:9)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

看起来这可能与解决方案 2有关。我不确定最后两个步骤会去哪里。

标签: javascriptnode.jsgithubgithub-apireferenceerror

解决方案


我安装babel-plugin-transform-regenerator并添加import 'babel-polyfill'到问题文件的顶部。似乎已经解决了这个问题,尽管它对我来说没有任何意义。


推荐阅读