a3c92311e3
# Introduction Fix unsafe resource path join with expected prefix at file storage directly Add early paths transversal detections in metadata validators
47 lines
1.9 KiB
TypeScript
47 lines
1.9 KiB
TypeScript
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 @typescripttypescript/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_EXECUTION_FAILED:
|
|
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:
|
|
throw new ForbiddenError(error);
|
|
default: {
|
|
return assertUnreachable(error.code);
|
|
}
|
|
}
|
|
}
|
|
throw error;
|
|
};
|