mirror of
https://github.com/makeplane/plane.git
synced 2025-12-16 11:57:56 +01:00
[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:
committed by
GitHub
parent
cacd1b489e
commit
0bc45e3047
@@ -13,6 +13,11 @@ import type { IIssueLabel } from "@plane/types";
|
||||
import { Input } from "@plane/ui";
|
||||
import { captureError, captureSuccess } from "@/helpers/event-tracker.helper";
|
||||
|
||||
// error codes
|
||||
const errorCodes = {
|
||||
LABEL_NAME_ALREADY_EXISTS: "LABEL_NAME_ALREADY_EXISTS",
|
||||
};
|
||||
|
||||
export type TLabelOperationsCallbacks = {
|
||||
createLabel: (data: Partial<IIssueLabel>) => Promise<IIssueLabel>;
|
||||
updateLabel: (labelId: string, data: Partial<IIssueLabel>) => Promise<IIssueLabel>;
|
||||
@@ -59,6 +64,23 @@ export const CreateUpdateLabelInline = observer(
|
||||
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) => {
|
||||
if (isSubmitting) return;
|
||||
|
||||
@@ -83,10 +105,12 @@ export const CreateUpdateLabelInline = observer(
|
||||
},
|
||||
error,
|
||||
});
|
||||
|
||||
const errorMessage = getErrorMessage(error, "create");
|
||||
setToast({
|
||||
title: "Error!",
|
||||
type: TOAST_TYPE.ERROR,
|
||||
message: error?.detail ?? error.error ?? t("common.something_went_wrong"),
|
||||
message: errorMessage,
|
||||
});
|
||||
reset(formData);
|
||||
});
|
||||
@@ -117,10 +141,11 @@ export const CreateUpdateLabelInline = observer(
|
||||
},
|
||||
error,
|
||||
});
|
||||
const errorMessage = getErrorMessage(error, "update");
|
||||
setToast({
|
||||
title: "Oops!",
|
||||
type: TOAST_TYPE.ERROR,
|
||||
message: error?.error ?? t("project_settings.labels.toast.error"),
|
||||
message: errorMessage,
|
||||
});
|
||||
reset(formData);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user