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

This commit is contained in:
nitin
2026-03-04 20:06:11 +05:30
committed by GitHub
parent aaa483c020
commit 07803f232f
2 changed files with 13 additions and 6 deletions
@@ -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.`;
@@ -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',
);
}