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:
1 parent
5c9ad93923
commit
ef4be48ea6
3 files changed
+20
-5
No files matched your search
@@ -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