From 138b37994a7d44ae5466bd447411ba1174c227b4 Mon Sep 17 00:00:00 2001 From: sblausten Date: Tue, 20 Dec 2022 11:57:22 +0100 Subject: [PATCH] Return 200 unless all fail Signed-off-by: sblausten --- plugins/tech-insights-backend/src/service/router.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/tech-insights-backend/src/service/router.ts b/plugins/tech-insights-backend/src/service/router.ts index e09114d2c7..969f2974d6 100644 --- a/plugins/tech-insights-backend/src/service/router.ts +++ b/plugins/tech-insights-backend/src/service/router.ts @@ -124,9 +124,14 @@ export async function createRouter< } }); const results = await Promise.all(tasks); - if (errors.length > 0) { + const noResults = + results.length === 0 || results.flatMap(r => r.results).length === 0; + if (errors.length > 0 && noResults) { return res.status(500).send({ errors, results }); } + if (errors.length > 0) { + return res.json({ errors, results }); + } return res.json(results); }); } else {