Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[WEB-4525] fix: project create/update error handling (#7429)

Anmol Singh Bhatia07c80bb02c05
diff --git a/apps/web/ce/components/projects/create/root.tsx b/apps/web/ce/components/projects/create/root.tsx
index aeb8b3aaee..71935fa2e4 100644
--- a/apps/web/ce/components/projects/create/root.tsx
+++ b/apps/web/ce/components/projects/create/root.tsx
@@ -99,45 +99,32 @@ export const CreateProjectForm: FC<TCreateProjectFormProps> = observer((props) =
// Handle the new error format where codes are nested in arrays under field names
const errorData = err?.data ?? {};
- // Check for specific error codes in the new format
- if (errorData.name?.includes("PROJECT_NAME_ALREADY_EXIST")) {
- setToast({
- type: TOAST_TYPE.ERROR,
- title: t("toast.error"),
- message: t("project_name_already_taken"),
- });
- }
-
- if (errorData?.identifier?.includes("PROJECT_IDENTIFIER_ALREADY_EXIST")) {
- setToast({
- type: TOAST_TYPE.ERROR,
- title: t("toast.error"),
- message: t("project_identifier_already_taken"),
- });
- }
+ const nameError = errorData.name?.includes("PROJECT_NAME_ALREADY_EXIST");
+ const identifierError = errorData?.identifier?.includes("PROJECT_IDENTIFIER_ALREADY_EXIST");
- // Handle other field-specific errors (excluding name and identifier which are handled above)
- Object.keys(errorData).forEach((field) => {
- // Skip name and identifier fields as they're handled separately above
- if (field === "name" || field === "identifier") return;
-
- const fieldErrors = errorData[field];
- if (Array.isArray(fieldErrors)) {
- fieldErrors.forEach((errorMessage) => {
- setToast({
- type: TOAST_TYPE.ERROR,
- title: t("error"),
- message: errorMessage,
- });
+ if (nameError || identifierError) {
+ if (nameError) {
+ setToast({
+ type: TOAST_TYPE.ERROR,
+ title: t("toast.error"),
+ message: t("project_name_already_taken"),
});
- } else if (typeof fieldErrors === "string") {
+ }
+
+ if (identifierError) {
setToast({
type: TOAST_TYPE.ERROR,
- title: t("error"),
- message: fieldErrors,
+ title: t("toast.error"),
+ message: t("project_identifier_already_taken"),
});
}
- });
+ } else {
+ setToast({
+ type: TOAST_TYPE.ERROR,
+ title: t("toast.error"),
+ message: t("something_went_wrong"),
+ });
+ }
} catch (error) {
// Fallback error handling if the error processing fails
console.error("Error processing API error:", error);
diff --git a/apps/web/core/components/project/form.tsx b/apps/web/core/components/project/form.tsx
index c93a316d84..452d9d0b66 100644
--- a/apps/web/core/components/project/form.tsx
+++ b/apps/web/core/components/project/form.tsx
@@ -116,45 +116,32 @@ export const ProjectDetailsForm: FC<IProjectDetailsForm> = (props) => {
// Handle the new error format where codes are nested in arrays under field names
const errorData = err ?? {};
- // Check for specific error codes in the new format
- if (errorData.name?.includes("PROJECT_NAME_ALREADY_EXIST")) {
- setToast({
- type: TOAST_TYPE.ERROR,
- title: t("toast.error"),
- message: t("project_name_already_taken"),
- });
- }
-
- if (errorData?.identifier?.includes("PROJECT_IDENTIFIER_ALREADY_EXIST")) {
- setToast({
- type: TOAST_TYPE.ERROR,
- title: t("toast.error"),
- message: t("project_identifier_already_taken"),
- });
- }
+ const nameError = errorData.name?.includes("PROJECT_NAME_ALREADY_EXIST");
+ const identifierError = errorData?.identifier?.includes("PROJECT_IDENTIFIER_ALREADY_EXIST");
- // Handle other field-specific errors (excluding name and identifier which are handled above)
- Object.keys(errorData).forEach((field) => {
- // Skip name and identifier fields as they're handled separately above
- if (field === "name" || field === "identifier") return;
-
- const fieldErrors = errorData[field];
- if (Array.isArray(fieldErrors)) {
- fieldErrors.forEach((errorMessage) => {
- setToast({
- type: TOAST_TYPE.ERROR,
- title: t("error"),
- message: errorMessage,
- });
+ if (nameError || identifierError) {
+ if (nameError) {
+ setToast({
+ type: TOAST_TYPE.ERROR,
+ title: t("toast.error"),
+ message: t("project_name_already_taken"),
});
- } else if (typeof fieldErrors === "string") {
+ }
+
+ if (identifierError) {
setToast({
type: TOAST_TYPE.ERROR,
- title: t("error"),
- message: fieldErrors,
+ title: t("toast.error"),
+ message: t("project_identifier_already_taken"),
});
}
- });
+ } else {
+ setToast({
+ type: TOAST_TYPE.ERROR,
+ title: t("toast.error"),
+ message: t("something_went_wrong"),
+ });
+ }
} catch (error) {
// Fallback error handling if the error processing fails
console.error("Error processing API error:", error);