fix(plugins/traffic): display scope errors

This commit is contained in:
Simon Lecoq
2023-03-13 21:16:10 -04:00
parent 941683988b
commit 05e244b3fc

View File

@@ -16,7 +16,15 @@ export default async function({login, imports, data, rest, q, account}, {enabled
//Get views stats from repositories //Get views stats from repositories
console.debug(`metrics/compute/${login}/plugins > traffic > querying api`) console.debug(`metrics/compute/${login}/plugins > traffic > querying api`)
const views = {count: 0, uniques: 0} const views = {count: 0, uniques: 0}
const response = [...await Promise.allSettled(repositories.map(({repo, owner}) => imports.filters.repo(`${owner}/${repo}`, skipped) ? rest.repos.getViews({owner, repo}) : {}))].filter(({status}) => status === "fulfilled").map(({value}) => value) const promised = [...await Promise.allSettled(repositories.map(({repo, owner}) => imports.filters.repo(`${owner}/${repo}`, skipped) ? rest.repos.getViews({owner, repo}) : {}))]
const response = promised.filter(({status}) => status === "fulfilled").map(({value}) => value)
//Handle error if all promises were rejected
if (promised.filter(({status}) => status === "rejected").length === promised.length) {
if (promised.map(({reason}) => reason.message).every(error => /must have push access to repository/i.test(error)))
throw {error: {message: "Insufficient token scopes"}}
throw new Error(promised[0].reason.message)
}
//Compute views //Compute views
console.debug(`metrics/compute/${login}/plugins > traffic > computing stats`) console.debug(`metrics/compute/${login}/plugins > traffic > computing stats`)