fix(front): correctly show error message when a tag is too short

Closes #1382

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2024-02-08 11:27:25 +01:00
parent 6a482b0d97
commit cba2075431
3 changed files with 26 additions and 5 deletions

View File

@@ -924,9 +924,28 @@ const handleError = (err: any) => {
console.error(err);
if (err.graphQLErrors !== undefined) {
err.graphQLErrors.forEach(({ message }: { message: string }) => {
notifier?.error(message);
});
err.graphQLErrors.forEach(
({
message,
field,
}: {
message: string | { slug?: string[] }[];
field: string;
}) => {
if (
field === "tags" &&
Array.isArray(message) &&
message.some((msg) => msg.slug)
) {
const finalMsg = message.find((msg) => msg.slug?.[0]);
notifier?.error(
t("Error while adding tag: {error}", { error: finalMsg?.slug?.[0] })
);
} else if (typeof message === "string") {
notifier?.error(message);
}
}
);
}
};