twenty / packages /twenty-server /src /engine /metadata-modules /logic-function /utils /logic-function-graphql-api-exception-handler.utils.ts
Jules
Initial clean CRM deployment with prebuilt assets
d9494a5
Raw
History Blame Contribute Delete
1.99 kB
import { assertUnreachable } from 'twenty-shared/utils';
import {
ConflictError,
ForbiddenError,
NotFoundError,
TimeoutError,
UserInputError,
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
import {
LogicFunctionException,
LogicFunctionExceptionCode,
} from 'src/engine/metadata-modules/logic-function/logic-function.exception';
// oxlint-disable-next-line typescript/no-explicit-any
export const logicFunctionGraphQLApiExceptionHandler = (error: any) => {
if (error instanceof LogicFunctionException) {
switch (error.code) {
case LogicFunctionExceptionCode.LOGIC_FUNCTION_NOT_FOUND:
throw new NotFoundError(error);
case LogicFunctionExceptionCode.LOGIC_FUNCTION_ALREADY_EXIST:
throw new ConflictError(error);
case LogicFunctionExceptionCode.LOGIC_FUNCTION_NOT_READY:
case LogicFunctionExceptionCode.LOGIC_FUNCTION_BUILDING:
case LogicFunctionExceptionCode.LOGIC_FUNCTION_EXECUTION_LIMIT_REACHED:
throw new ForbiddenError(error);
case LogicFunctionExceptionCode.LOGIC_FUNCTION_EXECUTION_TIMEOUT:
throw new TimeoutError(error);
case LogicFunctionExceptionCode.LOGIC_FUNCTION_CODE_UNCHANGED:
case LogicFunctionExceptionCode.LOGIC_FUNCTION_CREATE_FAILED:
case LogicFunctionExceptionCode.LOGIC_FUNCTION_INVALID_SEED_PROJECT:
case LogicFunctionExceptionCode.LOGIC_FUNCTION_PLATFORM_EXECUTION_ERROR:
case LogicFunctionExceptionCode.LOGIC_FUNCTION_LAYER_BUILD_FAILED:
throw error;
case LogicFunctionExceptionCode.LOGIC_FUNCTION_COMPILATION_FAILED:
case LogicFunctionExceptionCode.INVALID_LOGIC_FUNCTION_INPUT:
throw new UserInputError(error);
case LogicFunctionExceptionCode.LOGIC_FUNCTION_DISABLED:
case LogicFunctionExceptionCode.LOGIC_FUNCTION_PREBUILT_BUNDLE_NOT_INSTALLED:
throw new ForbiddenError(error);
default: {
return assertUnreachable(error.code);
}
}
}
throw error;
};