Search code examples
javascriptnode.jsgithubgithub-apireferenceerror

callback failing even though GitHub Installation access Token gets generated


I have this code for generating an Installation Access Token:

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}`);
    }
  });
});

It outputs Unable to authenticate so is failing at some point. My issue is that console.log('Installation Access Token: ${installationAccessToken}') outputs a token so I would expect the callback to succeed. Is there any reason why it's likely to fail?

Additional info

This is the actual error returned in the 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)

Looks like this might relate to Solution 2 of this. I'm not sure where the last two steps would go though.


Solution

  • I installed babel-plugin-transform-regenerator and added import 'babel-polyfill' to the top of the problem file. Seems to have resolved the issue although it doesn't really make sense to me.