Skip to content

Commit

Permalink
fix: handle errors in auth
Browse files Browse the repository at this point in the history
  • Loading branch information
EvaMart committed Sep 15, 2024
1 parent ec1638b commit 0e5bf97
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
36 changes: 21 additions & 15 deletions src/shared/helpers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@ const { Octokit, App } = require('octokit');
* @returns {Promise<App>} - A promise that resolves to an authenticated instance of octokit.
*/
async function authApp(appID, privateKeyPath) {

// reading the app private key from the appropriate file
const fs = require("fs");
var myKey = fs.readFileSync(privateKeyPath, "utf8");

console.debug(`appID: ${appID}`);
console.debug(`myKey: ${myKey}`);

const app = await new App({
appId: appID,
privateKey: myKey,
});

return app;

const fs = require("fs");

try {
// Reading the app private key from the appropriate file
var myKey = fs.readFileSync(privateKeyPath, "utf8");

console.debug(`appID: ${appID}`);
console.debug(`myKey: ${myKey}`);

// Creating the app instance
const app = await new App({
appId: appID,
privateKey: myKey,
});

return app;
} catch (error) {
// Log the error and return null or an appropriate value
console.error("Error in authApp:", error);
return null; // or throw new Error('Failed to authenticate app') if you want to propagate the error
}
}

/**
Expand Down
16 changes: 11 additions & 5 deletions src/shared/helpers/installation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
* @param {string} repo - The name of the repository.
* @returns {Promise<Object>} - A promise that resolves to the installation object.
*/
async function getInstallationID(app, owner, repo){
const installation = await app.octokit.request(`/repos/${owner}/${repo}/installation`);

return installation;

async function getInstallationID(app, owner, repo) {
try {
// Attempt to fetch the installation ID
const installation = await app.octokit.request(`/repos/${owner}/${repo}/installation`);

return installation;
} catch (error) {
// Log the error and return null or an appropriate value
console.error("Error in getInstallationID:", error);
return null; // or you could return a custom error object or throw an error if needed
}
}

module.exports = {
Expand Down

0 comments on commit 0e5bf97

Please sign in to comment.