From 5a3400f6ddda5c8a493d1d0e374d1c3fe2843933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 14 Jul 2024 07:47:54 +0200 Subject: [PATCH] TRCPErrorCause --- .../server/src/trpc/TRPCContextCreator.ts | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/server/src/trpc/TRPCContextCreator.ts b/packages/server/src/trpc/TRPCContextCreator.ts index 67df8c2..3a104c2 100644 --- a/packages/server/src/trpc/TRPCContextCreator.ts +++ b/packages/server/src/trpc/TRPCContextCreator.ts @@ -56,22 +56,52 @@ const mapErrors = (effect: Effect.Effect) => Effect.sandbox(effect).pipe( Effect.catchTags({ Die: cause => Effect.fail( - new TRPCError({ code: "INTERNAL_SERVER_ERROR", cause }) + new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + cause: new TRCPErrorCause(cause), + }) ), + Interrupt: cause => Effect.fail( - new TRPCError({ code: "INTERNAL_SERVER_ERROR", cause }) + new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + cause: new TRCPErrorCause(cause), + }) ), + Fail: cause => Effect.fail( - new TRPCError({ code: "INTERNAL_SERVER_ERROR", cause }) + new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + cause: new TRCPErrorCause(cause), + }) ), + Empty: cause => Effect.fail( - new TRPCError({ code: "INTERNAL_SERVER_ERROR", cause }) + new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + cause: new TRCPErrorCause(cause), + }) ), + Parallel: cause => Effect.fail( - new TRPCError({ code: "INTERNAL_SERVER_ERROR", cause }) + new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + cause: new TRCPErrorCause(cause), + }) ), + Sequential: cause => Effect.fail( - new TRPCError({ code: "INTERNAL_SERVER_ERROR", cause }) + new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + cause: new TRCPErrorCause(cause), + }) ), }) ) + + +export class TRCPErrorCause extends Error { + constructor(readonly cause: unknown) { + super() + } +}