Skip to content

The open alternative to Salesforce, designed for AI.

fix: use ForbiddenException in DevelopmentGuard to prevent Sentry noise (#18378)

nitin07803f232f0e
diff --git a/packages/twenty-server/src/engine/core-modules/graphql/utils/generate-graphql-error-from-error.util.ts b/packages/twenty-server/src/engine/core-modules/graphql/utils/generate-graphql-error-from-error.util.ts
index 9b417961d5e..8350bfcc2b9 100644
--- a/packages/twenty-server/src/engine/core-modules/graphql/utils/generate-graphql-error-from-error.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/graphql/utils/generate-graphql-error-from-error.util.ts
@@ -1,3 +1,5 @@
+import { HttpException } from '@nestjs/common';
+
import { type I18n } from '@lingui/core';
import { msg } from '@lingui/core/macro';
@@ -5,16 +7,17 @@ import {
BaseGraphQLError,
ErrorCode,
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
+import { convertExceptionToGraphQLError } from 'src/engine/utils/global-exception-handler.util';
import { CustomException } from 'src/utils/custom-exception';
export const generateGraphQLErrorFromError = (
error: Error | CustomException,
i18n: I18n,
) => {
- const graphqlError = new BaseGraphQLError(
- error.message,
- ErrorCode.INTERNAL_SERVER_ERROR,
- );
+ const graphqlError =
+ error instanceof HttpException
+ ? convertExceptionToGraphQLError(error)
+ : new BaseGraphQLError(error.message, ErrorCode.INTERNAL_SERVER_ERROR);
const defaultErrorMessage = msg`An error occurred.`;
diff --git a/packages/twenty-server/src/engine/guards/development.guard.ts b/packages/twenty-server/src/engine/guards/development.guard.ts
index f2561d217ed..6303df55595 100644
--- a/packages/twenty-server/src/engine/guards/development.guard.ts
+++ b/packages/twenty-server/src/engine/guards/development.guard.ts
@@ -1,4 +1,8 @@
-import { type CanActivate, Injectable } from '@nestjs/common';
+import {
+ type CanActivate,
+ ForbiddenException,
+ Injectable,
+} from '@nestjs/common';
import { NodeEnvironment } from 'src/engine/core-modules/twenty-config/interfaces/node-environment.interface';
@@ -15,7 +19,7 @@ export class DevelopmentGuard implements CanActivate {
nodeEnv !== NodeEnvironment.DEVELOPMENT &&
nodeEnv !== NodeEnvironment.TEST
) {
- throw new Error(
+ throw new ForbiddenException(
'This endpoint is only available in development or test environments',
);
}