Do not fail fast on run checks endpoint when a single check fails and return error message alongside any results that completed

Signed-off-by: sblausten <sam@roadie.io>
This commit is contained in:
sblausten
2022-12-20 08:56:22 +01:00
parent bb1122ba22
commit 7a38a31699
2 changed files with 24 additions and 5 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-tech-insights-backend': patch
---
Complete check results run when a single check errors so that we don't block other checks from working due to an error in a single check
@@ -103,16 +103,30 @@ export async function createRouter<
checks,
entities,
}: { checks: string[]; entities: CompoundEntityRef[] } = req.body;
let error = undefined;
const tasks = entities.map(async entity => {
const entityTriplet =
typeof entity === 'string' ? entity : stringifyEntityRef(entity);
const results = await factChecker.runChecks(entityTriplet, checks);
return {
entity: entityTriplet,
results,
};
try {
const results = await factChecker.runChecks(entityTriplet, checks);
return {
entity: entityTriplet,
results,
};
} catch (e: any) {
const errorMessage = `Failed to run check for entity ${entityTriplet} due to error: ${e.message}`;
logger.error(errorMessage);
error = errorMessage;
return {
entity: entityTriplet,
results: [],
};
}
});
const results = await Promise.all(tasks);
if (error) {
return res.status(500).send({ error, results });
}
return res.json(results);
});
} else {