Issue with Effect not catching InsufficientCreditsError as expected

const logic = (userId: string) =>
    Effect.gen(function* (_) {
        const userCredits = yield* getUserCredits(userId)
        console.log("User credits", userCredits)
        if (userCredits < 195) {
            console.log("User has insufficient credits")
            Effect.fail(new InsufficientCreditsError())
        }
        Effect.succeed(userCredits)
    })


I have this Effect which in my specific use case should fail

const program = logic(userId).pipe(
            Effect.catchTag("InsufficientCreditsError", (error) =>
                Effect.succeed(new Response(JSON.stringify({ success: false, error: "Insufficient credits" }), {
                    headers: { ...corsHeaders, "Content-Type": "application/json" },
                    status: 200,
                })),
            ),
        )

        Effect.runPromise(program).then((result) => {
            console.log("Result", result)
        })


I run the effect here and i expect my effect to catch this tag and return a new response to my client but it does not, i only get Result: "undefined"
Was this page helpful?