Wrapped the raw esbuild build error in a domain-specific `LogicFunctionException` with a new `LOGIC_FUNCTION_BUILD_FAILED` exception code. Previously, esbuild build failures from user code (syntax errors, unsupported features) propagated as unhandled `Error` instances all the way to Sentry, creating noise for what is fundamentally a user input validation issue — not an application bug.
Changes:
1. **`logic-function.exception.ts`** — Added `LOGIC_FUNCTION_BUILD_FAILED` enum value and its user-friendly message ("Function build failed. Please check your code for syntax errors.")
2. **`logic-function-graphql-api-exception-handler.utils.ts`** — Added `LOGIC_FUNCTION_BUILD_FAILED` to the switch case so it's handled as a known exception type (re-thrown as-is, same pattern as `CREATE_FAILED` and `INVALID_SEED_PROJECT`)
3. **`logic-function-resource.service.ts`** — Wrapped the `await build()` call in a try/catch that converts esbuild errors into `LogicFunctionException` with the build error message preserved for debugging
42 lines
1.6 KiB
TypeScript
42 lines
1.6 KiB
TypeScript
import { assertUnreachable } from 'twenty-shared/utils';
|
|
|
|
import {
|
|
ConflictError,
|
|
ForbiddenError,
|
|
NotFoundError,
|
|
TimeoutError,
|
|
} 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_BUILD_FAILED:
|
|
throw error;
|
|
case LogicFunctionExceptionCode.LOGIC_FUNCTION_DISABLED:
|
|
throw new ForbiddenError(error);
|
|
default: {
|
|
return assertUnreachable(error.code);
|
|
}
|
|
}
|
|
}
|
|
throw error;
|
|
};
|