mapEffectErrorsToTRPC
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { TRPCError } from "@trpc/server"
|
||||||
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express"
|
import type { CreateExpressContextOptions } from "@trpc/server/adapters/express"
|
||||||
import { Context, Effect, Layer, Runtime } from "effect"
|
import { Context, Effect, Layer, Runtime } from "effect"
|
||||||
import type { Services } from "../Services"
|
import type { Services } from "../Services"
|
||||||
@@ -23,3 +24,21 @@ export module TRPCContextCreator {
|
|||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const mapEffectErrorsToTRPC = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
||||||
|
Effect.sandbox(effect).pipe(
|
||||||
|
Effect.catchTags({
|
||||||
|
Die: cause => Effect.fail(
|
||||||
|
new TRPCError({ code: "INTERNAL_SERVER_ERROR" })
|
||||||
|
),
|
||||||
|
|
||||||
|
Interrupt: cause => Effect.fail(
|
||||||
|
new TRPCError({ code: "INTERNAL_SERVER_ERROR" })
|
||||||
|
),
|
||||||
|
|
||||||
|
Fail: cause => Effect.fail(
|
||||||
|
new TRPCError({ code: "INTERNAL_SERVER_ERROR" })
|
||||||
|
),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user