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

This commit is contained in:
Alex van Andel
2023-06-23 07:03:45 +02:00
committed by GitHub
parent 2d6eebcd8a
commit 52936f60b4
8 changed files with 34 additions and 16 deletions
+3 -7
View File
@@ -168,18 +168,14 @@ const EventTypePage = (props: EventTypeSetupProps) => {
}
if (err.data?.code === "UNAUTHORIZED") {
message = `${err.data.code}: You are not able to update this event`;
message = `${err.data.code}: ${t("error_event_type_unauthorized_update")}`;
}
if (err.data?.code === "PARSE_ERROR" || err.data?.code === "BAD_REQUEST") {
message = `${err.data.code}: ${err.message}`;
message = `${err.data.code}: ${t(err.message)}`;
}
if (message) {
showToast(message, "error");
} else {
showToast(err.message, "error");
}
showToast(message ? t(message) : t(err.message), "error");
},
});
@@ -339,6 +339,11 @@
"cancelling_event_recurring": "The event is one instance of a recurring event.",
"cancelling_all_recurring": "These are all remaining instances in the recurring event.",
"error_with_status_code_occured": "An error with status code {{status}} occurred.",
"error_event_type_url_duplicate": "An event type with this URL already exists.",
"error_event_type_unauthorized_create": "You are not able to create this event",
"error_event_type_unauthorized_update": "You are not able to edit this event",
"error_workflow_unauthorized_create": "You are not able to create this workflow",
"error_schedule_unauthorized_create": "You are not able to create this schedule",
"booking_already_cancelled": "This booking was already canceled",
"booking_already_accepted_rejected": "This booking was already accepted or rejected",
"go_back_home": "Go back home",
@@ -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({