Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

don't fail if one of the pids is inaccessible

Blue Mouse24ebe6fad850
diff --git a/backend/apps/cloud/src/analytics/analytics.controller.ts b/backend/apps/cloud/src/analytics/analytics.controller.ts
index c32709d01..7ee1839bd 100644
--- a/backend/apps/cloud/src/analytics/analytics.controller.ts
+++ b/backend/apps/cloud/src/analytics/analytics.controller.ts
@@ -29,6 +29,8 @@ import {
ForbiddenException,
Response,
Header,
+ HttpException,
+ HttpStatus,
} from '@nestjs/common'
import UAParser from 'ua-parser-js'
@@ -846,6 +848,8 @@ export class AnalyticsController {
} = data
const pidsArray = getPIDsArray(pids, pid)
+ const validPids = []
+
const validationPromises = _map(pidsArray, async currentPID => {
await this.analyticsService.checkProjectAccess(
currentPID,
@@ -854,12 +858,25 @@ export class AnalyticsController {
)
await this.analyticsService.checkBillingAccess(currentPID)
+
+ validPids.push(currentPID)
})
- await Promise.all(validationPromises)
+ try {
+ await Promise.all(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.getAnalyticsSummary(
- pidsArray,
+ validPids,
period,
from,
to,
@@ -985,6 +1002,8 @@ export class AnalyticsController {
const { pids, pid } = data
const pidsArray = getPIDsArray(pids, pid)
+ const validPids = []
+
const validationPromises = _map(pidsArray, async currentPID => {
await this.analyticsService.checkProjectAccess(
currentPID,
@@ -993,13 +1012,25 @@ export class AnalyticsController {
)
await this.analyticsService.checkBillingAccess(currentPID)
+
+ validPids.push(currentPID)
})
- await Promise.all(validationPromises)
+ try {
+ await Promise.all(validationPromises)
+ // eslint-disable-next-line no-empty
+ } catch {}
+
+ 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,
+ )
+ }
const result = {}
- const keyCountPromises = _map(pidsArray, async currentPID => {
+ const keyCountPromises = _map(validPids, async currentPID => {
result[currentPID] =
await this.analyticsService.getOnlineUserCount(currentPID)
})