fix: configure correct error message for duplicate event type slug (#24928)
* fix/duplicate-event-type-to-existing slug * use existing pattern to to verify the conflict on slug
This commit is contained in:
@@ -457,6 +457,7 @@
|
||||
"bookerlayout_error_unknown_layout": "The layout you selected is not a valid layout.",
|
||||
"bookerlayout_override_global_settings": "You can manage this for all your event types in Settings -> <0>Appearance</0> or <1>Override</1> for this event only.",
|
||||
"unexpected_error_try_again": "An unexpected error occurred. Try again.",
|
||||
"duplicate_event_slug_conflict": "An event type with this URL already exists. Please try a different URL.",
|
||||
"sunday_time_error": "Invalid time on Sunday",
|
||||
"monday_time_error": "Invalid time on Monday",
|
||||
"tuesday_time_error": "Invalid time on Tuesday",
|
||||
|
||||
@@ -93,6 +93,13 @@ const DuplicateDialog = () => {
|
||||
if (err instanceof HttpError) {
|
||||
const message = `${err.statusCode}: ${err.message}`;
|
||||
showToast(message, "error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (err.data?.code === "CONFLICT") {
|
||||
const message = t("duplicate_event_slug_conflict");
|
||||
showToast(message, "error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (err.data?.code === "INTERNAL_SERVER_ERROR" || err.data?.code === "BAD_REQUEST") {
|
||||
|
||||
@@ -95,11 +95,11 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
|
||||
workflows,
|
||||
hashedLink,
|
||||
destinationCalendar,
|
||||
|
||||
|
||||
id: _id,
|
||||
|
||||
|
||||
webhooks: _webhooks,
|
||||
|
||||
|
||||
schedule: _schedule,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore - descriptionAsSafeHTML is added on the fly using a prisma middleware it shouldn't be used to create event type. Such a property doesn't exist on schema
|
||||
@@ -227,9 +227,16 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
|
||||
};
|
||||
} catch (error) {
|
||||
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
|
||||
// unique constraint violation
|
||||
|
||||
if (Array.isArray(error.meta?.target) && error.meta?.target.includes("slug")) {
|
||||
throw new TRPCError({
|
||||
code: "CONFLICT",
|
||||
message: "duplicate_event_slug_conflict",
|
||||
});
|
||||
}
|
||||
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
code: "CONFLICT",
|
||||
message: "Unique constraint violation while creating a duplicate event.",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user