Skip to content

Commit 3d8ba1c

Browse files
Adapt mutation error handling (#2019)
<!-- Ensure the title clearly reflects what was changed. Provide a clear and concise description of the changes made. The PR should only contain the changes related to the issue, and no other unrelated changes. --> Part of OPS-3673
1 parent d294558 commit 3d8ba1c

23 files changed

Lines changed: 71 additions & 101 deletions

File tree

packages/react-ui/src/app/features/ai/lib/ai-model-selector-hook.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { aiAssistantChatApi } from '@/app/features/ai/lib/ai-assistant-chat-api';
2+
import { isForbiddenMutationError } from '@/app/interceptors/interceptor-utils';
23
import { toast } from '@openops/components/ui';
34
import { useMutation } from '@tanstack/react-query';
45
import { AxiosError } from 'axios';
@@ -33,12 +34,14 @@ export const useAiModelSelector = ({
3334
setSelectedModel(data.model);
3435
},
3536
onError: (error: AxiosError) => {
36-
toast({
37-
title: t('Error'),
38-
variant: 'destructive',
39-
description: error.message,
40-
duration: 3000,
41-
});
37+
if (!isForbiddenMutationError(error)) {
38+
toast({
39+
title: t('Error'),
40+
variant: 'destructive',
41+
description: error.message,
42+
duration: 3000,
43+
});
44+
}
4245
},
4346
});
4447

packages/react-ui/src/app/features/benchmark/use-benchmark-wizard-navigation.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { INTERNAL_ERROR_TOAST, toast } from '@openops/components/ui';
1+
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
22
import {
33
BenchmarkCreationResult,
44
BenchmarkWizardRequest,
@@ -63,9 +63,7 @@ export const useBenchmarkWizardNavigation = (
6363
provider: string;
6464
request: BenchmarkWizardRequest;
6565
}) => benchmarkApi.getWizardStep(provider, request),
66-
onError: () => {
67-
toast(INTERNAL_ERROR_TOAST);
68-
},
66+
onError: handleMutationError,
6967
});
7068

7169
const { mutateAsync: runCreateBenchmark, isPending: isCreatingBenchmark } =
@@ -82,9 +80,7 @@ export const useBenchmarkWizardNavigation = (
8280
setWizardPhase('benchmark-ready');
8381
onBenchmarkCreated?.(result);
8482
},
85-
onError: () => {
86-
toast(INTERNAL_ERROR_TOAST);
87-
},
83+
onError: handleMutationError,
8884
});
8985

9086
const handleNextFromInitial = async () => {

packages/react-ui/src/app/features/builder/blocks-selector/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
CardListItem,
88
CardListItemSkeleton,
99
Input,
10-
INTERNAL_ERROR_TOAST,
1110
ItemListMetadata,
1211
Popover,
1312
PopoverContent,
@@ -37,6 +36,7 @@ import {
3736
} from '@/app/features/builder/blocks-selector/block-tag-group';
3837
import { useBuilderStateContext } from '@/app/features/builder/builder-hooks';
3938
import { useApplyOperationAndPushToHistory } from '@/app/features/builder/flow-version-undo-redo/hooks/apply-operation-and-push-to-history';
39+
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
4040
import {
4141
Action,
4242
ActionType,
@@ -246,7 +246,7 @@ const BlockSelector = ({
246246
},
247247
onError: (e) => {
248248
console.error(e);
249-
toast(INTERNAL_ERROR_TOAST);
249+
handleMutationError(e);
250250
},
251251
});
252252

packages/react-ui/src/app/features/builder/builder-header/hooks/lock-and-publish.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useFlowVersionUndoRedo } from '@/app/features/builder/flow-version-undo-redo/hooks/flow-version-undo-redo';
22
import { flowsApi } from '@/app/features/flows/lib/flows-api';
3-
import { INTERNAL_ERROR_TOAST, toast } from '@openops/components/ui';
3+
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
4+
import { toast } from '@openops/components/ui';
45
import { FlowOperationType } from '@openops/shared';
56
import { useMutation } from '@tanstack/react-query';
67
import { t } from 'i18next';
@@ -33,9 +34,7 @@ const useLockAndPublish = () => {
3334
setFlow(flow);
3435
setVersion(flow.version);
3536
},
36-
onError: () => {
37-
toast(INTERNAL_ERROR_TOAST);
38-
},
37+
onError: handleMutationError,
3938
},
4039
);
4140

packages/react-ui/src/app/features/builder/builder-hooks.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import {
2-
AI_CHAT_CONTAINER_SIZES,
3-
INTERNAL_ERROR_TOAST,
4-
toast,
5-
} from '@openops/components/ui';
1+
import { AI_CHAT_CONTAINER_SIZES } from '@openops/components/ui';
62
import { useMutation } from '@tanstack/react-query';
73
import { createContext, useContext } from 'react';
84
import { create, StateCreator, useStore } from 'zustand';
95
import { devtools } from 'zustand/middleware';
106

117
import { flowsApi } from '@/app/features/flows/lib/flows-api';
8+
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
129
import {
1310
Flow,
1411
FlowOperationRequest,
@@ -418,9 +415,7 @@ export const useSwitchToDraft = () => {
418415
setVersion(flow.version);
419416
exitRun();
420417
},
421-
onError: () => {
422-
toast(INTERNAL_ERROR_TOAST);
423-
},
418+
onError: handleMutationError,
424419
});
425420
return {
426421
switchToDraft,

packages/react-ui/src/app/features/builder/flow-canvas/widgets/test-flow-widget.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {
22
Button,
33
cn,
4-
INTERNAL_ERROR_TOAST,
54
isMacUserAgent,
6-
toast,
75
Tooltip,
86
TooltipContent,
97
TooltipTrigger,
@@ -21,6 +19,7 @@ import {
2119
useExecuteRiskyFlowDialog,
2220
} from '@/app/features/flows/components/execute-risky-flow-dialog/execute-risky-flow-dialog';
2321
import { flowsApi } from '@/app/features/flows/lib/flows-api';
22+
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
2423
import { FlowRun, FlowVersion, isNil, TriggerType } from '@openops/shared';
2524
import { Settings } from 'lucide-react';
2625
import { stepTestOutputHooks } from '../../test-step/step-test-output-hooks';
@@ -57,7 +56,7 @@ const TestFlowWidget = ({ flowVersion, setRun }: TestFlowWidgetProps) => {
5756
),
5857
onError: (error) => {
5958
console.error(error);
60-
toast(INTERNAL_ERROR_TOAST);
59+
handleMutationError(error);
6160
},
6261
});
6362

packages/react-ui/src/app/features/builder/flow-versions/flow-versions-card.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import {
1414
DropdownMenuContent,
1515
DropdownMenuItem,
1616
DropdownMenuTrigger,
17-
INTERNAL_ERROR_TOAST,
1817
LoadingSpinner,
19-
toast,
2018
Tooltip,
2119
TooltipContent,
2220
TooltipTrigger,
@@ -42,6 +40,7 @@ import { useBuilderStateContext } from '@/app/features/builder/builder-hooks';
4240
import { LeftSideBarType } from '@/app/features/builder/builder-types';
4341
import { FlowVersionStateDot } from '@/app/features/flows/components/flow-version-state-dot';
4442
import { flowsApi } from '@/app/features/flows/lib/flows-api';
43+
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
4544
import { formatUtils } from '@/app/lib/utils';
4645

4746
type UseAsDraftOptionProps = {
@@ -144,8 +143,8 @@ const FlowVersionDetailsCard = React.memo(
144143
);
145144
},
146145
onError: (error) => {
147-
toast(INTERNAL_ERROR_TOAST);
148146
console.error(error);
147+
handleMutationError(error);
149148
},
150149
});
151150

@@ -175,8 +174,8 @@ const FlowVersionDetailsCard = React.memo(
175174
);
176175
},
177176
onError: (error) => {
178-
toast(INTERNAL_ERROR_TOAST);
179177
console.error(error);
178+
handleMutationError(error);
180179
},
181180
});
182181

packages/react-ui/src/app/features/builder/run-list/flow-run-card.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import {
22
Button,
33
CardListItem,
44
cn,
5-
INTERNAL_ERROR_TOAST,
65
LoadingSpinner,
7-
toast,
86
} from '@openops/components/ui';
97
import { StopwatchIcon } from '@radix-ui/react-icons';
108
import { useMutation } from '@tanstack/react-query';
@@ -16,6 +14,7 @@ import { useBuilderStateContext } from '@/app/features/builder/builder-hooks';
1614
import { flowRunUtils } from '@/app/features/flow-runs/lib/flow-run-utils';
1715
import { flowRunsApi } from '@/app/features/flow-runs/lib/flow-runs-api';
1816
import { flowsApi } from '@/app/features/flows/lib/flows-api';
17+
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
1918
import { formatUtils } from '@/app/lib/utils';
2019
import { FlowRun, isNil, PopulatedFlow } from '@openops/shared';
2120
import { LeftSideBarType } from '../builder-types';
@@ -54,8 +53,8 @@ const FlowRunCard = React.memo((params: FlowRunCardProps) => {
5453
setLeftSidebar(LeftSideBarType.RUN_DETAILS);
5554
},
5655
onError: (error) => {
57-
toast(INTERNAL_ERROR_TOAST);
5856
console.error(error);
57+
handleMutationError(error);
5958
},
6059
});
6160

packages/react-ui/src/app/features/builder/test-step/test-action-section.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
Button,
3-
Dot,
4-
INTERNAL_ERROR_TOAST,
5-
useToast,
6-
} from '@openops/components/ui';
1+
import { Button, Dot } from '@openops/components/ui';
72
import { useMutation, useQueryClient } from '@tanstack/react-query';
83
import { t } from 'i18next';
94
import React, { useEffect, useState } from 'react';
@@ -17,6 +12,7 @@ import {
1712
RiskyStepConfirmationMessages,
1813
} from '@/app/features/builder/test-step/test-risky-step-confirmation-messages';
1914
import { flowsApi } from '@/app/features/flows/lib/flows-api';
15+
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
2016
import { formatUtils } from '@/app/lib/utils';
2117
import {
2218
Action,
@@ -47,7 +43,6 @@ const TestActionSection = React.memo(
4743
onTestCallback,
4844
readOnly,
4945
}: TestActionComponentProps) => {
50-
const { toast } = useToast();
5146
const [errorMessage, setErrorMessage] = useState<string | undefined>(
5247
undefined,
5348
);
@@ -107,7 +102,7 @@ const TestActionSection = React.memo(
107102
},
108103
onError: (error) => {
109104
console.error(error);
110-
toast(INTERNAL_ERROR_TOAST);
105+
handleMutationError(error);
111106
},
112107
});
113108

packages/react-ui/src/app/features/builder/test-step/test-trigger-section.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import {
44
AlertTitle,
55
Button,
66
Dot,
7-
INTERNAL_ERROR_TOAST,
87
LoadingSpinner,
98
Select,
109
SelectContent,
1110
SelectItem,
1211
SelectTrigger,
1312
SelectValue,
14-
toast,
1513
} from '@openops/components/ui';
1614
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
1715
import dayjs from 'dayjs';
@@ -24,6 +22,7 @@ import { useFormContext } from 'react-hook-form';
2422
import { QueryKeys } from '@/app/constants/query-keys';
2523
import { blocksHooks } from '@/app/features/blocks/lib/blocks-hook';
2624
import { triggerEventsApi } from '@/app/features/flows/lib/trigger-events-api';
25+
import { handleMutationError } from '@/app/interceptors/interceptor-utils';
2726
import { formatUtils } from '@/app/lib/utils';
2827
import {
2928
CATCH_WEBHOOK,
@@ -110,9 +109,7 @@ const TestTriggerSection = React.memo(
110109
mutationFn: (data: unknown) => {
111110
return triggerEventsApi.saveTriggerMockdata(flowId, data);
112111
},
113-
onError: () => {
114-
toast(INTERNAL_ERROR_TOAST);
115-
},
112+
onError: handleMutationError,
116113
onSuccess: async (result) => {
117114
updateSelectedData(result);
118115
},

0 commit comments

Comments
 (0)