fix: show specific error when duplicate tag name is entered

This commit is contained in:
Naidu_4444
2025-06-23 11:44:51 +00:00
parent e5fa4328e1
commit 3f9f097260
3 changed files with 20 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import "server-only";
import { validateInputs } from "@/lib/utils/validate";
import { Prisma } from "@prisma/client";
import { prisma } from "@formbricks/database";
import { ZId, ZString } from "@formbricks/types/common";
import { TTag } from "@formbricks/types/tags";
@@ -34,8 +35,18 @@ export const updateTagName = async (id: string, name: string): Promise<TTag> =>
});
return tag;
} catch (error) {
throw error;
} catch (error: any) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
return {
data: null,
error: { message: "already exists" },
};
}
return {
data: null,
error: { message: error.message || "Something went wrong" },
};
}
};

View File

@@ -26,7 +26,6 @@ export const ProjectLookSettingsPage = async (props: { params: Promise<{ environ
}
const canRemoveBranding = await getWhiteLabelPermission(organization.billing.plan);
return (
<PageContentWrapper>
<PageHeader pageTitle={t("common.project_configuration")}>

View File

@@ -72,22 +72,23 @@ export const SingleTag: React.FC<SingleTagProps> = ({
defaultValue={tagName}
onBlur={(e) => {
updateTagNameAction({ tagId, name: e.target.value.trim() }).then((updateTagNameResponse) => {
if (updateTagNameResponse?.data) {
const response = updateTagNameResponse?.data;
if (response?.id) {
setUpdateTagError(false);
toast.success(t("environments.project.tags.tag_updated"));
} else {
const errorMessage = getFormattedErrorMessage(updateTagNameResponse);
const errorMessage = response?.error?.message ?? "";
if (
errorMessage?.includes(
t("environments.project.tags.unique_constraint_failed_on_the_fields")
)
errorMessage.toLowerCase().includes("already exists") ||
errorMessage.toLowerCase().includes("unique constraint failed")
) {
toast.error(t("environments.project.tags.tag_already_exists"), {
duration: 2000,
icon: <AlertCircleIcon className="h-5 w-5 text-orange-500" />,
});
} else {
toast.error(errorMessage ?? t("common.something_went_wrong_please_try_again"), {
toast.error(t("common.something_went_wrong_please_try_again"), {
duration: 2000,
});
}