Skip to content

Commit

Permalink
Try without error wrapping to see if error message is clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
tibdex committed Sep 9, 2023
1 parent efd52bf commit 495b461
Showing 1 changed file with 34 additions and 43 deletions.
77 changes: 34 additions & 43 deletions src/fetch-installation-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,40 @@ export const fetchInstallationToken = async ({

let installationId: number;

try {
switch (installationRetrievalDetails.mode) {
case "id":
({ id: installationId } = installationRetrievalDetails);
break;
case "organization":
({
data: { id: installationId },
} = await octokit.request("GET /orgs/{org}/installation", {
org: installationRetrievalDetails.org,
}));
break;
case "repository":
({
data: { id: installationId },
} = await octokit.request("GET /repos/{owner}/{repo}/installation", {
owner: installationRetrievalDetails.owner,
repo: installationRetrievalDetails.repo,
}));
break;
case "user":
({
data: { id: installationId },
} = await octokit.request("GET /users/{username}/installation", {
username: installationRetrievalDetails.username,
}));
break;
}
} catch (error: unknown) {
throw new Error("Could not get retrieve installation.", { cause: error });
switch (installationRetrievalDetails.mode) {
case "id":
({ id: installationId } = installationRetrievalDetails);
break;
case "organization":
({
data: { id: installationId },
} = await octokit.request("GET /orgs/{org}/installation", {
org: installationRetrievalDetails.org,
}));
break;
case "repository":
({
data: { id: installationId },
} = await octokit.request("GET /repos/{owner}/{repo}/installation", {
owner: installationRetrievalDetails.owner,
repo: installationRetrievalDetails.repo,
}));
break;
case "user":
({
data: { id: installationId },
} = await octokit.request("GET /users/{username}/installation", {
username: installationRetrievalDetails.username,
}));
break;
}

try {
const {
data: { token },
} = await octokit.rest.apps.createInstallationAccessToken({
installation_id: installationId,
permissions,
});
return token;
} catch (error: unknown) {
throw new Error("Could not create installation access token.", {
cause: error,
});
}
const {
data: { token },
} = await octokit.rest.apps.createInstallationAccessToken({
installation_id: installationId,
permissions,
repositories,
});
return token;
};

0 comments on commit 495b461

Please sign in to comment.