mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 15:36:48 +00:00
Show new error component when saving pipeline fails (#8511)
* fix: show new error component when saving pipeline fails * fix: minor refactor --------- Co-authored-by: Aditya Singh <adityasingh@Adityas-MacBook-Pro.local>
This commit is contained in:
parent
ddb08b3883
commit
a7ce6da7d1
@ -1,24 +1,20 @@
|
||||
import axios from 'api';
|
||||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler';
|
||||
import { ErrorResponseHandlerV2 } from 'api/ErrorResponseHandlerV2';
|
||||
import { AxiosError } from 'axios';
|
||||
import { ErrorResponse, SuccessResponse } from 'types/api';
|
||||
import { ErrorV2Resp, SuccessResponseV2 } from 'types/api';
|
||||
import { Pipeline } from 'types/api/pipeline/def';
|
||||
import { Props } from 'types/api/pipeline/post';
|
||||
|
||||
const post = async (
|
||||
props: Props,
|
||||
): Promise<SuccessResponse<Pipeline> | ErrorResponse> => {
|
||||
const post = async (props: Props): Promise<SuccessResponseV2<Pipeline>> => {
|
||||
try {
|
||||
const response = await axios.post('/logs/pipelines', props.data);
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
error: null,
|
||||
message: response.data.status,
|
||||
payload: response.data.data,
|
||||
httpStatusCode: response.status,
|
||||
data: response.data.data,
|
||||
};
|
||||
} catch (error) {
|
||||
return ErrorResponseHandler(error as AxiosError);
|
||||
ErrorResponseHandlerV2(error as AxiosError<ErrorV2Resp>);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import savePipeline from 'api/pipeline/post';
|
||||
import { useNotifications } from 'hooks/useNotifications';
|
||||
import { isEqual, isUndefined } from 'lodash-es';
|
||||
import cloneDeep from 'lodash-es/cloneDeep';
|
||||
import { useErrorModal } from 'providers/ErrorModalProvider';
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
@ -18,6 +19,7 @@ import React, {
|
||||
import { DndProvider } from 'react-dnd';
|
||||
import { HTML5Backend } from 'react-dnd-html5-backend';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import APIError from 'types/api/error';
|
||||
import {
|
||||
ActionMode,
|
||||
ActionType,
|
||||
@ -95,6 +97,7 @@ function PipelineListsView({
|
||||
pipelineData,
|
||||
refetchPipelineLists,
|
||||
}: PipelineListsViewProps): JSX.Element {
|
||||
const { showErrorModal } = useErrorModal();
|
||||
const [pipelineForm] = Form.useForm<PipelineData>();
|
||||
const { t } = useTranslation(['pipeline', 'common']);
|
||||
const [modal, contextHolder] = Modal.useModal();
|
||||
@ -442,17 +445,15 @@ function PipelineListsView({
|
||||
delete pipelineData?.id;
|
||||
return pipelineData;
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await savePipeline({
|
||||
data: { pipelines: modifiedPipelineData },
|
||||
});
|
||||
|
||||
if (response.statusCode === 200) {
|
||||
refetchPipelineLists();
|
||||
setActionMode(ActionMode.Viewing);
|
||||
setShowSaveButton(undefined);
|
||||
|
||||
const pipelinesInDB = response.payload?.pipelines || [];
|
||||
const pipelinesInDB = response.data?.pipelines || [];
|
||||
setCurrPipelineData(pipelinesInDB);
|
||||
setPrevPipelineData(pipelinesInDB);
|
||||
|
||||
@ -470,7 +471,7 @@ function PipelineListsView({
|
||||
enabled: pipelinesInDB.filter((p) => p.enabled).length,
|
||||
source: 'signoz-ui',
|
||||
});
|
||||
} else {
|
||||
} catch (error) {
|
||||
modifiedPipelineData.forEach((item: PipelineData) => {
|
||||
const pipelineData = item;
|
||||
pipelineData.id = v4();
|
||||
@ -478,10 +479,7 @@ function PipelineListsView({
|
||||
});
|
||||
setActionMode(ActionMode.Editing);
|
||||
setShowSaveButton(ActionMode.Editing);
|
||||
notifications.error({
|
||||
message: 'Error',
|
||||
description: response.error || t('something_went_wrong'),
|
||||
});
|
||||
showErrorModal(error as APIError);
|
||||
setCurrPipelineData(modifiedPipelineData);
|
||||
setPrevPipelineData(modifiedPipelineData);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user