javascript - 即使生成了 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有关。我不确定最后两个步骤会去哪里。
解决方案
我安装babel-plugin-transform-regenerator
并添加import 'babel-polyfill'
到问题文件的顶部。似乎已经解决了这个问题,尽管它对我来说没有任何意义。
推荐阅读
- python - 在随机位置创建一个零和一的numpy数组
- json - Tslint exclude 不能正常工作,React-Dropzone
- python - 从 Python 中的文本中收集 ID
- c++ - gss_accept_sec_context() 失败:请求了不受支持的机制
- php - 强制重定向到 CodeIgniter 3 中的安装页面
- python - 室温警报到电子邮件 - Raspberry Pi
- reactjs - ReferenceError:NextJS 项目中未定义 CustomEvent
- django - django - DecimalField 充当默认值为 0.00 的浮点字段?
- brackets - 未能为括号安装自动前缀扩展
- python - 两种方法的时间复杂度(一种使用 dict 和其他列表)