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

* chore: project create/update error handling

* chore: code refactor
This commit is contained in:
Anmol Singh Bhatia 2025-07-18 14:25:28 +05:30 committed by GitHub
parent 1ad792b4bb
commit 07c80bb02c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 68 deletions

View file

@ -99,8 +99,11 @@ 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")) {
const nameError = errorData.name?.includes("PROJECT_NAME_ALREADY_EXIST");
const identifierError = errorData?.identifier?.includes("PROJECT_IDENTIFIER_ALREADY_EXIST");
if (nameError || identifierError) {
if (nameError) {
setToast({
type: TOAST_TYPE.ERROR,
title: t("toast.error"),
@ -108,36 +111,20 @@ export const CreateProjectForm: FC<TCreateProjectFormProps> = observer((props) =
});
}
if (errorData?.identifier?.includes("PROJECT_IDENTIFIER_ALREADY_EXIST")) {
if (identifierError) {
setToast({
type: TOAST_TYPE.ERROR,
title: t("toast.error"),
message: t("project_identifier_already_taken"),
});
}
// 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) => {
} else {
setToast({
type: TOAST_TYPE.ERROR,
title: t("error"),
message: errorMessage,
});
});
} else if (typeof fieldErrors === "string") {
setToast({
type: TOAST_TYPE.ERROR,
title: t("error"),
message: fieldErrors,
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);

View file

@ -116,8 +116,11 @@ 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")) {
const nameError = errorData.name?.includes("PROJECT_NAME_ALREADY_EXIST");
const identifierError = errorData?.identifier?.includes("PROJECT_IDENTIFIER_ALREADY_EXIST");
if (nameError || identifierError) {
if (nameError) {
setToast({
type: TOAST_TYPE.ERROR,
title: t("toast.error"),
@ -125,36 +128,20 @@ export const ProjectDetailsForm: FC<IProjectDetailsForm> = (props) => {
});
}
if (errorData?.identifier?.includes("PROJECT_IDENTIFIER_ALREADY_EXIST")) {
if (identifierError) {
setToast({
type: TOAST_TYPE.ERROR,
title: t("toast.error"),
message: t("project_identifier_already_taken"),
});
}
// 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) => {
} else {
setToast({
type: TOAST_TYPE.ERROR,
title: t("error"),
message: errorMessage,
});
});
} else if (typeof fieldErrors === "string") {
setToast({
type: TOAST_TYPE.ERROR,
title: t("error"),
message: fieldErrors,
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);