Return all errors

Signed-off-by: sblausten <sam@roadie.io>
This commit is contained in:
sblausten
2022-12-20 11:45:33 +01:00
parent 7a38a31699
commit 4d1094bef4
@@ -103,7 +103,7 @@ export async function createRouter<
checks,
entities,
}: { checks: string[]; entities: CompoundEntityRef[] } = req.body;
let error = undefined;
const errors: string[] = [];
const tasks = entities.map(async entity => {
const entityTriplet =
typeof entity === 'string' ? entity : stringifyEntityRef(entity);
@@ -116,7 +116,7 @@ export async function createRouter<
} catch (e: any) {
const errorMessage = `Failed to run check for entity ${entityTriplet} due to error: ${e.message}`;
logger.error(errorMessage);
error = errorMessage;
errors.push(errorMessage);
return {
entity: entityTriplet,
results: [],
@@ -124,8 +124,8 @@ export async function createRouter<
}
});
const results = await Promise.all(tasks);
if (error) {
return res.status(500).send({ error, results });
if (errors.length > 0) {
return res.status(500).send({ errors, results });
}
return res.json(results);
});