[WEB-5503] fix: enhance error handling for label creation and update operations (#8175)
* fix: enhance error handling for label creation and update operations * fix: improve error handling for label creation and update operations * refactor: change error codes from enum to object for label operations * refactor: update error code references in label handling to use consistent naming * fix: improve error handling for label creation and update
This commit is contained in:
parent
cacd1b489e
commit
0bc45e3047
1 changed files with 27 additions and 2 deletions
|
|
@ -13,6 +13,11 @@ import type { IIssueLabel } from "@plane/types";
|
||||||
import { Input } from "@plane/ui";
|
import { Input } from "@plane/ui";
|
||||||
import { captureError, captureSuccess } from "@/helpers/event-tracker.helper";
|
import { captureError, captureSuccess } from "@/helpers/event-tracker.helper";
|
||||||
|
|
||||||
|
// error codes
|
||||||
|
const errorCodes = {
|
||||||
|
LABEL_NAME_ALREADY_EXISTS: "LABEL_NAME_ALREADY_EXISTS",
|
||||||
|
};
|
||||||
|
|
||||||
export type TLabelOperationsCallbacks = {
|
export type TLabelOperationsCallbacks = {
|
||||||
createLabel: (data: Partial<IIssueLabel>) => Promise<IIssueLabel>;
|
createLabel: (data: Partial<IIssueLabel>) => Promise<IIssueLabel>;
|
||||||
updateLabel: (labelId: string, data: Partial<IIssueLabel>) => Promise<IIssueLabel>;
|
updateLabel: (labelId: string, data: Partial<IIssueLabel>) => Promise<IIssueLabel>;
|
||||||
|
|
@ -59,6 +64,23 @@ export const CreateUpdateLabelInline = observer(
|
||||||
if (onClose) onClose();
|
if (onClose) onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const getErrorMessage = (error: any, operation: "create" | "update"): string => {
|
||||||
|
const errorData = error ?? {};
|
||||||
|
|
||||||
|
const labelError = errorData.name?.includes(errorCodes.LABEL_NAME_ALREADY_EXISTS);
|
||||||
|
if (labelError) {
|
||||||
|
return t("label.create.already_exists");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to general error messages
|
||||||
|
if (operation === "create") {
|
||||||
|
return errorData?.detail ?? errorData?.error ?? t("common.something_went_wrong");
|
||||||
|
}
|
||||||
|
|
||||||
|
return errorData?.error ?? t("project_settings.labels.toast.error");
|
||||||
|
};
|
||||||
|
|
||||||
const handleLabelCreate: SubmitHandler<IIssueLabel> = async (formData) => {
|
const handleLabelCreate: SubmitHandler<IIssueLabel> = async (formData) => {
|
||||||
if (isSubmitting) return;
|
if (isSubmitting) return;
|
||||||
|
|
||||||
|
|
@ -83,10 +105,12 @@ export const CreateUpdateLabelInline = observer(
|
||||||
},
|
},
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const errorMessage = getErrorMessage(error, "create");
|
||||||
setToast({
|
setToast({
|
||||||
title: "Error!",
|
title: "Error!",
|
||||||
type: TOAST_TYPE.ERROR,
|
type: TOAST_TYPE.ERROR,
|
||||||
message: error?.detail ?? error.error ?? t("common.something_went_wrong"),
|
message: errorMessage,
|
||||||
});
|
});
|
||||||
reset(formData);
|
reset(formData);
|
||||||
});
|
});
|
||||||
|
|
@ -117,10 +141,11 @@ export const CreateUpdateLabelInline = observer(
|
||||||
},
|
},
|
||||||
error,
|
error,
|
||||||
});
|
});
|
||||||
|
const errorMessage = getErrorMessage(error, "update");
|
||||||
setToast({
|
setToast({
|
||||||
title: "Oops!",
|
title: "Oops!",
|
||||||
type: TOAST_TYPE.ERROR,
|
type: TOAST_TYPE.ERROR,
|
||||||
message: error?.error ?? t("project_settings.labels.toast.error"),
|
message: errorMessage,
|
||||||
});
|
});
|
||||||
reset(formData);
|
reset(formData);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue