[WEB-4525] fix: project create/update error handling (#7429)
* chore: project create/update error handling * chore: code refactor
This commit is contained in:
parent
1ad792b4bb
commit
07c80bb02c
2 changed files with 42 additions and 68 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue