Unable get installation token immediately after `installation.created` webhook

I have a handler for the installation.created webhook that attempts to add a secret to all fo the repos that the user has allowed access to my GitHub App. I am using @octokit/rest and sometimes, I get a 404 when trying to get the installation token – e.g.

  return new Octokit({
    authStrategy: createAppAuth,
    auth: {
      id: GITHUB_APP_ID,
      privateKey: GITHUB_APP_PRIVATE_KEY,
      installationId,
    },
  });

This does not always happens, sometimes it succeeds, sometimes it fails with a 404.

When redelivered, it succeeds:

It looks like the octokit constructor is async, and I can’t seem to catch the promise rejection either to try to retry.

:wave: @billyvg: Thanks for sharing these details here! While I can’t explain why that specific 404 was returned upon creating an installation token, I’m wondering if you’ve tried implementing a sleep or delay function before retrying the request again? On a cursory search of the octokit/rest.js documentation, has a section for automation retries that might be worth checking out as well. Keen to hear other’s thoughts on this as well! :ear: