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!

subscription error: returning 402 payment required instead of 403 forbidden status code

Blue Mouseb2f2d83da048
diff --git a/apps/production/src/alert/alert.controller.ts b/apps/production/src/alert/alert.controller.ts
index 321221e7b..ec7db5c8f 100644
--- a/apps/production/src/alert/alert.controller.ts
+++ b/apps/production/src/alert/alert.controller.ts
@@ -11,6 +11,8 @@ import {
Post,
ForbiddenException,
BadRequestException,
+ HttpException,
+ HttpStatus,
} from '@nestjs/common'
import { In } from 'typeorm'
import { ApiTags, ApiResponse } from '@nestjs/swagger'
@@ -19,15 +21,11 @@ import * as _map from 'lodash/map'
import * as _omit from 'lodash/omit'
import * as _pick from 'lodash/pick'
-import { UserService } from 'src/user/user.service'
-import { ProjectService } from 'src/project/project.service'
-import { AppLoggerService } from 'src/logger/logger.service'
-import {
- UserType,
- ACCOUNT_PLANS,
- PlanCode,
-} from 'src/user/entities/user.entity'
-import { JwtAccessTokenGuard } from 'src/auth/guards'
+import { UserService } from '../user/user.service'
+import { ProjectService } from '../project/project.service'
+import { AppLoggerService } from '../logger/logger.service'
+import { UserType, ACCOUNT_PLANS, PlanCode } from '../user/entities/user.entity'
+import { JwtAccessTokenGuard } from '../auth/guards'
import { CurrentUserId } from '../auth/decorators/current-user-id.decorator'
import { Roles } from '../auth/decorators/roles.decorator'
import { Alert } from './entity/alert.entity'
@@ -122,14 +120,16 @@ export class AlertController {
const alertsCount = await this.alertService.count({ project: In(pids) })
if (user.planCode === PlanCode.none) {
- throw new ForbiddenException(
+ throw new HttpException(
'You cannot create new alerts due to no active subscription. Please upgrade your account plan to continue.',
+ HttpStatus.PAYMENT_REQUIRED,
)
}
if (alertsCount >= (maxAlerts || ALERTS_MAXIMUM)) {
- throw new ForbiddenException(
+ throw new HttpException(
`You cannot create more than ${maxAlerts} alerts on your account plan. Please upgrade to be able to create more alerts.`,
+ HttpStatus.PAYMENT_REQUIRED,
)
}
diff --git a/apps/production/src/analytics/analytics.service.ts b/apps/production/src/analytics/analytics.service.ts
index d8bbf3073..310ca6bcd 100644
--- a/apps/production/src/analytics/analytics.service.ts
+++ b/apps/production/src/analytics/analytics.service.ts
@@ -26,7 +26,8 @@ import {
Injectable,
BadRequestException,
InternalServerErrorException,
- ForbiddenException,
+ HttpException,
+ HttpStatus,
UnprocessableEntityException,
PreconditionFailedException,
} from '@nestjs/common'
@@ -381,8 +382,9 @@ export class AnalyticsService {
}
if (project.admin.planCode === PlanCode.none) {
- throw new ForbiddenException(
+ throw new HttpException(
'You cannot send analytics to this project due to no active subscription. Please upgrade your account plan to continue sending analytics.',
+ HttpStatus.PAYMENT_REQUIRED,
)
}
@@ -391,8 +393,9 @@ export class AnalyticsService {
ACCOUNT_PLANS[project.admin.planCode].monthlyUsageLimit || 0
if (count >= maxCount) {
- throw new ForbiddenException(
+ throw new HttpException(
'You have exceeded the available monthly request limit for your account. Please upgrade your account plan if you need more requests.',
+ HttpStatus.PAYMENT_REQUIRED,
)
}
diff --git a/apps/production/src/project/project.controller.ts b/apps/production/src/project/project.controller.ts
index 9586154e6..27513ee60 100644
--- a/apps/production/src/project/project.controller.ts
+++ b/apps/production/src/project/project.controller.ts
@@ -12,10 +12,11 @@ import {
HttpCode,
NotFoundException,
ForbiddenException,
+ HttpException,
+ HttpStatus,
Headers,
Header,
Patch,
- HttpStatus,
ConflictException,
Res,
} from '@nestjs/common'
@@ -303,8 +304,9 @@ export class ProjectController {
}
if (user.planCode === PlanCode.none) {
- throw new ForbiddenException(
+ throw new HttpException(
'You cannot create new projects due to no active subscription. Please upgrade your account plan to continue.',
+ HttpStatus.PAYMENT_REQUIRED,
)
}
@@ -317,8 +319,9 @@ export class ProjectController {
) >= (maxProjects || PROJECTS_MAXIMUM),
)
) {
- throw new ForbiddenException(
+ throw new HttpException(
`You cannot create more than ${maxProjects} projects on your account plan. Please upgrade to be able to create more projects.`,
+ HttpStatus.PAYMENT_REQUIRED,
)
}
} else if (