Add try catch for event type duplicate, fixed catch error loggin (#6130)

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
pull/5897/head^2
alannnc 2022-12-20 14:38:15 -07:00 committed by GitHub
parent 49bf14b196
commit 9487819ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 104 additions and 101 deletions

View File

@ -43,12 +43,12 @@ const DuplicateDialog = () => {
showToast(message, "error"); showToast(message, "error");
} }
if (err.data?.code === "BAD_REQUEST") { if (err.data?.code === "INTERNAL_SERVER_ERROR" || err.data?.code === "BAD_REQUEST") {
const message = `${err.data.code}: URL already exists.`; const message = t("unexpected_error_try_again");
showToast(message, "error"); showToast(message, "error");
} }
if (err.data?.code === "UNAUTHORIZED") { if (err.data?.code === "UNAUTHORIZED" || err.data?.code === "FORBIDDEN") {
const message = `${err.data.code}: You are not able to create this event`; const message = `${err.data.code}: You are not able to create this event`;
showToast(message, "error"); showToast(message, "error");
} }

View File

@ -622,6 +622,7 @@ export const eventTypesRouter = router({
}; };
}), }),
duplicate: eventOwnerProcedure.input(EventTypeDuplicateInput.strict()).mutation(async ({ ctx, input }) => { duplicate: eventOwnerProcedure.input(EventTypeDuplicateInput.strict()).mutation(async ({ ctx, input }) => {
try {
const { id: originalEventTypeId, title: newEventTitle, slug: newSlug } = input; const { id: originalEventTypeId, title: newEventTitle, slug: newSlug } = input;
const eventType = await ctx.prisma.eventType.findUnique({ const eventType = await ctx.prisma.eventType.findUnique({
where: { where: {
@ -654,7 +655,6 @@ export const eventTypesRouter = router({
throw new TRPCError({ code: "FORBIDDEN" }); throw new TRPCError({ code: "FORBIDDEN" });
} }
} }
throw new TRPCError({ code: "FORBIDDEN" });
} }
const { const {
@ -678,12 +678,12 @@ export const eventTypesRouter = router({
...rest ...rest
} = eventType; } = eventType;
const data: Prisma.EventTypeCreateInput = { const data: Prisma.EventTypeUncheckedCreateInput = {
...rest, ...rest,
title: newEventTitle, title: newEventTitle,
slug: newSlug, slug: newSlug,
locations: locations ?? undefined, locations: locations ?? undefined,
team: team ? { connect: { id: team.id } } : undefined, teamId: team ? team.id : undefined,
users: users ? { connect: users.map((user) => ({ id: user.id })) } : undefined, users: users ? { connect: users.map((user) => ({ id: user.id })) } : undefined,
recurringEvent: recurringEvent || undefined, recurringEvent: recurringEvent || undefined,
bookingLimits: bookingLimits ?? undefined, bookingLimits: bookingLimits ?? undefined,
@ -728,5 +728,8 @@ export const eventTypesRouter = router({
return { return {
eventType: newEventType, eventType: newEventType,
}; };
} catch (error) {
throw new TRPCError({ code: "INTERNAL_SERVER_ERROR" });
}
}), }),
}); });