fix: Various errors & 500 error on duplicate url when editing (#9731)

This commit is contained in:
Alex van Andel authored and GitHub committed 2023-06-23 07:03:45 +02:00
1 parent 2d6eebcd8a
commit 52936f60b4
8 files changed
+34 -16

No files matched your search

@@ -226,7 +226,7 @@ function EventWorkflowsTab(props: Props) {
}
if (err.data?.code === "UNAUTHORIZED") {
const message = `${err.data.code}: You are not able to create this workflow`;
const message = `${err.data.code}: ${t("error_workflow_unauthorized_create")}`;
showToast(message, "error");
}
},
@@ -40,7 +40,7 @@ function WorkflowsPage() {
}
if (err.data?.code === "UNAUTHORIZED") {
const message = `${err.data.code}: You are not able to create this workflow`;
const message = `${err.data.code}: ${t("error_workflow_unauthorized_create")}`;
showToast(message, "error");
}
},
@@ -127,12 +127,12 @@ export default function CreateEventTypeDialog({
}
if (err.data?.code === "BAD_REQUEST") {
const message = `${err.data.code}: URL already exists.`;
const message = `${err.data.code}: ${t("error_event_type_url_duplicate")}`;
showToast(message, "error");
}
if (err.data?.code === "UNAUTHORIZED") {
const message = `${err.data.code}: You are not able to create this event`;
const message = `${err.data.code}: ${t("error_event_type_unauthorized_create")}`;
showToast(message, "error");
}
},
@@ -65,7 +65,7 @@ const DuplicateDialog = () => {
}
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}: ${t("error_event_type_unauthorized_create")}`;
showToast(message, "error");
}
},
@@ -56,7 +56,7 @@ export function NewScheduleButton({
}
if (err.data?.code === "UNAUTHORIZED") {
const message = `${err.data.code}: You are not able to create this event`;
const message = `${err.data.code}: ${t("error_schedule_unauthorized_create")}`;
showToast(message, "error");
}
},
@@ -298,10 +298,27 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
});
}
}
const updatedEventType = await ctx.prisma.eventType.update({
where: { id },
data,
const updatedEventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
slug: true,
schedulingType: true,
});
let updatedEventType: Prisma.EventTypeGetPayload<{ select: typeof updatedEventTypeSelect }>;
try {
updatedEventType = await ctx.prisma.eventType.update({
where: { id },
data,
select: updatedEventTypeSelect,
});
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
if (e.code === "P2002") {
// instead of throwing a 500 error, catch the conflict and throw a 400 error.
throw new TRPCError({ message: "error_event_type_url_duplicate", code: "BAD_REQUEST" });
}
}
throw e;
}
// Handling updates to children event types (managed events types)
await updateChildrenEventTypes({