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 9b417961d5..8350bfcc2b 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 f2561d217e..6303df5559 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', ); }