Skip to content

Commit

Permalink
don't fail if one of the pids is inaccessible
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaumaus committed Dec 19, 2024
1 parent 6c0a28c commit 24ebe6f
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions backend/apps/cloud/src/analytics/analytics.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
ForbiddenException,
Response,
Header,
HttpException,
HttpStatus,
} from '@nestjs/common'
import UAParser from 'ua-parser-js'

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
})
Expand Down

0 comments on commit 24ebe6f

Please sign in to comment.