Effect CommunityEC
Effect Community3w ago
3 replies
stanisław

Recovering from defect

Effect.runPromise(
    Effect.gen(function* () {
        const gamesService = yield* GamesService;
        const value = gamesService.getOne(slug);
        const failureOrSuccess = yield* Effect.either(value);

        return Either.match(failureOrSuccess, {
            onLeft: (error) => {
                switch (error._tag) {
                    case "GameNotFoundError":
                        throw new NotFoundError(`Game with slug ${slug} was not found`);
                }
            },
            onRight: (value) => value,
        });
    })
        .pipe(Effect.provide(GamesRepository.Default))
        .pipe(Effect.provide(GamesService.Default)),
);


This program might crash because getOne in repository under the hood can call Effect.die

I am getting this error that die throws inside onError callback, how can i check if something is an error thrown from
die
?
Was this page helpful?