Skip to content

Commit 54dbdbb

Browse files
fix: re-throw TRPCErrors in duplicate handler catch block and assert specific error codes in tests
Co-Authored-By: ali@cal.com <alishahbaz7@gmail.com>
1 parent 536278f commit 54dbdbb

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

packages/trpc/server/routers/viewer/eventTypes/heavy/duplicate.handler.integration-test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ describe("duplicateHandler - integration", () => {
243243
teamId: team1.id,
244244
},
245245
})
246-
).rejects.toThrow(TRPCError);
246+
).rejects.toMatchObject({
247+
code: "FORBIDDEN",
248+
});
247249
});
248250

249251
it("should throw CONFLICT when duplicating with an existing slug", async () => {

packages/trpc/server/routers/viewer/eventTypes/heavy/duplicate.handler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
225225
eventType: newEventType,
226226
};
227227
} catch (error) {
228+
if (error instanceof TRPCError) {
229+
throw error;
230+
}
228231
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
229232

230233
if (Array.isArray(error.meta?.target) && error.meta?.target.includes("slug")) {

0 commit comments

Comments
 (0)