Skip to content

Commit

Permalink
fix:Simplify-error-handling(asyncapi#3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshaydewan committed Oct 21, 2024
1 parent 3a8f69a commit 41aaa49
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions scripts/dashboard/build-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,26 @@ async function getHotDiscussions(discussions) {
};
} catch (e) {
console.error(
`there was some issues while parsing this item: ${JSON.stringify(
`There was some issues while parsing this item: ${JSON.stringify(
discussion
)}`
);
throw e;
throw e; // Throw the error instead of logging
}
})
);
result.sort((ElemA, ElemB) => ElemB.score - ElemA.score);
const filteredResult = result.filter(issue => issue.author !== 'asyncapi-bot');
return filteredResult.slice(0, 12);
}

async function writeToFile(content) {
writeFileSync(
resolve(__dirname, '..', '..', 'dashboard.json'),
JSON.stringify(content, null, ' ')
);
}

async function mapGoodFirstIssues(issues) {
return issues.map((issue) => ({
id: issue.id,
Expand All @@ -87,7 +89,6 @@ function getLabel(issue, filter) {
return result && result.name.split('/')[1];
}


function monthsSince(date) {
const seconds = Math.floor((new Date() - new Date(date)) / 1000);
// 2592000 = number of seconds in a month = 30 * 24 * 60 * 60
Expand All @@ -112,7 +113,7 @@ async function getDiscussions(query, pageSize, endCursor = null) {
`limit = ${result.rateLimit.limit}`,
`remaining = ${result.rateLimit.remaining}`,
`resetAt = ${result.rateLimit.resetAt}`
)
);
}

const hasNextPage = result.search.pageInfo.hasNextPage;
Expand All @@ -126,23 +127,25 @@ async function getDiscussions(query, pageSize, endCursor = null) {
}
} catch (e) {
console.error(e);
throw e; // Throw the error instead of logging
}
}

async function getDiscussionByID(isPR, id) {
try {
let result = await graphql(isPR ? Queries.pullRequestById : Queries.issueById, {
id,
headers: {
authorization: `token ${process.env.GITHUB_TOKEN}`,
},

}
);
});
return result;
} catch (e) {
console.error(e);
throw e; // Throw the error instead of logging
}
}

async function start() {
try {
const [issues, PRs, rawGoodFirstIssues] = await Promise.all([
Expand All @@ -157,10 +160,12 @@ async function start() {
]);
writeToFile({ hotDiscussions, goodFirstIssues });
} catch (e) {
console.log('There were some issues parsing data from github.')
console.log('There were some issues parsing data from github.');
console.log(e);
throw e; // Throw the error instead of logging
}
}

start();

module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID }
module.exports = { getLabel, monthsSince, mapGoodFirstIssues, getHotDiscussions, getDiscussionByID };

0 comments on commit 41aaa49

Please sign in to comment.