Clean step and edge errors (#14261)
- add filters for both resolvers - map to gql errors Should fix https://github.com/twentyhq/core-team-issues/issues/996
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
import { Catch, type ExceptionFilter } from '@nestjs/common';
|
||||
|
||||
import { assertUnreachable } from 'twenty-shared/utils';
|
||||
|
||||
import { NotFoundError } from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
||||
import {
|
||||
WorkflowVersionEdgeException,
|
||||
WorkflowVersionEdgeExceptionCode,
|
||||
} from 'src/modules/workflow/common/exceptions/workflow-version-edge.exception';
|
||||
|
||||
export const handleWorkflowVersionEdgeException = (
|
||||
exception: WorkflowVersionEdgeException,
|
||||
) => {
|
||||
switch (exception.code) {
|
||||
case WorkflowVersionEdgeExceptionCode.NOT_FOUND:
|
||||
throw new NotFoundError(exception);
|
||||
default: {
|
||||
assertUnreachable(exception.code);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Catch(WorkflowVersionEdgeException)
|
||||
export class WorkflowVersionEdgeGraphqlApiExceptionFilter
|
||||
implements ExceptionFilter
|
||||
{
|
||||
catch(exception: WorkflowVersionEdgeException) {
|
||||
handleWorkflowVersionEdgeException(exception);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import { Catch, type ExceptionFilter } from '@nestjs/common';
|
||||
|
||||
import { assertUnreachable } from 'twenty-shared/utils';
|
||||
|
||||
import {
|
||||
InternalServerError,
|
||||
NotFoundError,
|
||||
UserInputError,
|
||||
} from 'src/engine/core-modules/graphql/utils/graphql-errors.util';
|
||||
import {
|
||||
WorkflowVersionStepException,
|
||||
WorkflowVersionStepExceptionCode,
|
||||
} from 'src/modules/workflow/common/exceptions/workflow-version-step.exception';
|
||||
|
||||
export const handleWorkflowVersionStepException = (
|
||||
exception: WorkflowVersionStepException,
|
||||
) => {
|
||||
switch (exception.code) {
|
||||
case WorkflowVersionStepExceptionCode.INVALID_REQUEST:
|
||||
throw new UserInputError(exception);
|
||||
case WorkflowVersionStepExceptionCode.NOT_FOUND:
|
||||
throw new NotFoundError(exception);
|
||||
case WorkflowVersionStepExceptionCode.CODE_STEP_FAILURE:
|
||||
throw new InternalServerError(exception);
|
||||
default: {
|
||||
assertUnreachable(exception.code);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Catch(WorkflowVersionStepException)
|
||||
export class WorkflowVersionStepGraphqlApiExceptionFilter
|
||||
implements ExceptionFilter
|
||||
{
|
||||
catch(exception: WorkflowVersionStepException) {
|
||||
handleWorkflowVersionStepException(exception);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -3,6 +3,9 @@ import { Args, Mutation, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { PreventNestToAutoLogGraphqlErrorsFilter } from 'src/engine/core-modules/graphql/filters/prevent-nest-to-auto-log-graphql-errors.filter';
|
||||
import { ResolverValidationPipe } from 'src/engine/core-modules/graphql/pipes/resolver-validation.pipe';
|
||||
import { CreateWorkflowVersionEdgeInput } from 'src/engine/core-modules/workflow/dtos/create-workflow-version-edge-input.dto';
|
||||
import { WorkflowVersionStepChangesDTO } from 'src/engine/core-modules/workflow/dtos/workflow-version-step-changes.dto';
|
||||
import { WorkflowVersionEdgeGraphqlApiExceptionFilter } from 'src/engine/core-modules/workflow/filters/workflow-version-edge-graphql-api-exception.filter';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
||||
import { SettingsPermissionsGuard } from 'src/engine/guards/settings-permissions.guard';
|
||||
@@ -10,8 +13,6 @@ import { UserAuthGuard } from 'src/engine/guards/user-auth.guard';
|
||||
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
import { PermissionFlagType } from 'src/engine/metadata-modules/permissions/constants/permission-flag-type.constants';
|
||||
import { PermissionsGraphqlApiExceptionFilter } from 'src/engine/metadata-modules/permissions/utils/permissions-graphql-api-exception.filter';
|
||||
import { CreateWorkflowVersionEdgeInput } from 'src/engine/core-modules/workflow/dtos/create-workflow-version-edge-input.dto';
|
||||
import { WorkflowVersionStepChangesDTO } from 'src/engine/core-modules/workflow/dtos/workflow-version-step-changes.dto';
|
||||
import { WorkflowVersionEdgeWorkspaceService } from 'src/modules/workflow/workflow-builder/workflow-version-edge/workflow-version-edge.workspace-service';
|
||||
|
||||
@Resolver()
|
||||
@@ -24,6 +25,7 @@ import { WorkflowVersionEdgeWorkspaceService } from 'src/modules/workflow/workfl
|
||||
@UseFilters(
|
||||
PermissionsGraphqlApiExceptionFilter,
|
||||
PreventNestToAutoLogGraphqlErrorsFilter,
|
||||
WorkflowVersionEdgeGraphqlApiExceptionFilter,
|
||||
)
|
||||
export class WorkflowVersionEdgeResolver {
|
||||
constructor(
|
||||
|
||||
+3
-1
@@ -11,6 +11,8 @@ import { SubmitFormStepInput } from 'src/engine/core-modules/workflow/dtos/submi
|
||||
import { UpdateWorkflowRunStepInput } from 'src/engine/core-modules/workflow/dtos/update-workflow-run-step-input.dto';
|
||||
import { UpdateWorkflowVersionStepInput } from 'src/engine/core-modules/workflow/dtos/update-workflow-version-step-input.dto';
|
||||
import { WorkflowActionDTO } from 'src/engine/core-modules/workflow/dtos/workflow-step.dto';
|
||||
import { WorkflowVersionStepChangesDTO } from 'src/engine/core-modules/workflow/dtos/workflow-version-step-changes.dto';
|
||||
import { WorkflowVersionStepGraphqlApiExceptionFilter } from 'src/engine/core-modules/workflow/filters/workflow-version-step-graphql-api-exception.filter';
|
||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
|
||||
import { SettingsPermissionsGuard } from 'src/engine/guards/settings-permissions.guard';
|
||||
@@ -21,7 +23,6 @@ import { PermissionsGraphqlApiExceptionFilter } from 'src/engine/metadata-module
|
||||
import { WorkflowVersionStepWorkspaceService } from 'src/modules/workflow/workflow-builder/workflow-version-step/workflow-version-step.workspace-service';
|
||||
import { WorkflowActionType } from 'src/modules/workflow/workflow-executor/workflow-actions/types/workflow-action.type';
|
||||
import { WorkflowRunWorkspaceService } from 'src/modules/workflow/workflow-runner/workflow-run/workflow-run.workspace-service';
|
||||
import { WorkflowVersionStepChangesDTO } from 'src/engine/core-modules/workflow/dtos/workflow-version-step-changes.dto';
|
||||
|
||||
@Resolver()
|
||||
@UsePipes(ResolverValidationPipe)
|
||||
@@ -33,6 +34,7 @@ import { WorkflowVersionStepChangesDTO } from 'src/engine/core-modules/workflow/
|
||||
@UseFilters(
|
||||
PermissionsGraphqlApiExceptionFilter,
|
||||
PreventNestToAutoLogGraphqlErrorsFilter,
|
||||
WorkflowVersionStepGraphqlApiExceptionFilter,
|
||||
)
|
||||
export class WorkflowVersionStepResolver {
|
||||
constructor(
|
||||
|
||||
Reference in New Issue
Block a user