The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
fix(server): stop rate-limit throttler exceptions from reaching Sentry (#24931)
Charles Bochet9c38f1abadb6
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-oauth/application-oauth.resolver.ts b/packages/twenty-server/src/engine/core-modules/application/application-oauth/application-oauth.resolver.tsindex bf2cc13135b..5f099bce515 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-oauth/application-oauth.resolver.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-oauth/application-oauth.resolver.ts@@ -13,6 +13,7 @@ import { ApplicationTokenPairDTO } from 'src/engine/core-modules/application/appimport { AuthGraphqlApiExceptionFilter } from 'src/engine/core-modules/auth/filters/auth-graphql-api-exception.filter';import { ApplicationTokenService } from 'src/engine/core-modules/auth/token/services/application-token.service';import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';+import { ThrottlerGraphqlApiExceptionFilter } from 'src/engine/core-modules/throttler/filters/throttler-graphql-api-exception.filter';import { ThrottlerService } from 'src/engine/core-modules/throttler/throttler.service';import { type WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';import { AuthUserWorkspaceId } from 'src/engine/decorators/auth/auth-user-workspace-id.decorator';@@ -27,7 +28,11 @@ const APP_TOKEN_RATE_LIMIT_WINDOW_MS = 30_000;@UsePipes(ResolverValidationPipe)@MetadataResolver()-@UseFilters(ApplicationExceptionFilter, AuthGraphqlApiExceptionFilter)+@UseFilters(+ ApplicationExceptionFilter,+ AuthGraphqlApiExceptionFilter,+ ThrottlerGraphqlApiExceptionFilter,+)@UseGuards(WorkspaceAuthGuard)export class ApplicationOAuthResolver {constructor(diff --git a/packages/twenty-server/src/engine/core-modules/throttler/throttler.exception.ts b/packages/twenty-server/src/engine/core-modules/throttler/throttler.exception.tsindex 4010f0cd2a6..8b4adeebb7c 100644--- a/packages/twenty-server/src/engine/core-modules/throttler/throttler.exception.ts+++ b/packages/twenty-server/src/engine/core-modules/throttler/throttler.exception.ts@@ -1,3 +1,5 @@+import { HttpStatus } from '@nestjs/common';+import { type MessageDescriptor } from '@lingui/core';import { msg } from '@lingui/core/macro';import { assertUnreachable } from 'twenty-shared/utils';@@ -28,6 +30,7 @@ export class ThrottlerException extends CustomException<ThrottlerExceptionCode>super(message, code, {userFriendlyMessage:userFriendlyMessage ?? getThrottlerExceptionUserFriendlyMessage(code),+ statusCode: HttpStatus.TOO_MANY_REQUESTS,});}}diff --git a/packages/twenty-server/src/engine/utils/__tests__/global-exception-handler.util.spec.ts b/packages/twenty-server/src/engine/utils/__tests__/global-exception-handler.util.spec.tsindex 2d9d7707497..3e07571a634 100644--- a/packages/twenty-server/src/engine/utils/__tests__/global-exception-handler.util.spec.ts+++ b/packages/twenty-server/src/engine/utils/__tests__/global-exception-handler.util.spec.ts@@ -1,5 +1,9 @@import { RetryableLogicFunctionError } from 'twenty-shared/logic-function';+import {+ ThrottlerException,+ ThrottlerExceptionCode,+} from 'src/engine/core-modules/throttler/throttler.exception';import { shouldCaptureException } from 'src/engine/utils/global-exception-handler.util';describe('shouldCaptureException', () => {@@ -13,6 +17,17 @@ describe('shouldCaptureException', () => {).toBe(false);});+ it('does not capture a rate-limit throttler exception', () => {+ expect(+ shouldCaptureException(+ new ThrottlerException(+ 'Limit reached (30 tokens per 30000 ms)',+ ThrottlerExceptionCode.LIMIT_REACHED,+ ),+ ),+ ).toBe(false);+ });+it('continues to capture an unexpected error', () => {expect(shouldCaptureException(new Error('Unexpected failure'))).toBe(true);});