From d6b016b070fb1943e24814ffeaeb1a635236e466 Mon Sep 17 00:00:00 2001 From: Blue Mouse Date: Thu, 19 Dec 2024 12:55:16 +0000 Subject: [PATCH] Promise.all -> Promise.allSettled --- .../src/analytics/analytics.controller.ts | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/apps/cloud/src/analytics/analytics.controller.ts b/backend/apps/cloud/src/analytics/analytics.controller.ts index 7ee1839bd..f0e297fdb 100644 --- a/backend/apps/cloud/src/analytics/analytics.controller.ts +++ b/backend/apps/cloud/src/analytics/analytics.controller.ts @@ -863,7 +863,7 @@ export class AnalyticsController { }) try { - await Promise.all(validationPromises) + await Promise.allSettled(validationPromises) } catch { // eslint-disable-next-line no-empty } @@ -903,16 +903,31 @@ export class AnalyticsController { } = data const pidsArray = getPIDsArray(pids, pid) + const validPids = [] + const validationPromises = _map(pidsArray, async currentPID => { await this.analyticsService.checkProjectAccess(currentPID, uid) await this.analyticsService.checkBillingAccess(currentPID) + + validPids.push(currentPID) }) - await Promise.all(validationPromises) + try { + await Promise.allSettled(validationPromises) + } catch { + // eslint-disable-next-line no-empty + } + + if (_isEmpty(validPids)) { + throw new HttpException( + 'The data could not be loaded for the selected projects. It is possible that the projects are not accessible to you or the account owner has been suspended.', + HttpStatus.PAYMENT_REQUIRED, + ) + } return this.analyticsService.getCaptchaSummary( - pidsArray, + validPids, period, from, to, @@ -1017,7 +1032,7 @@ export class AnalyticsController { }) try { - await Promise.all(validationPromises) + await Promise.allSettled(validationPromises) // eslint-disable-next-line no-empty } catch {}