Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to report Either<DecodeError, A> #59

Open
aldex32 opened this issue Mar 31, 2022 · 1 comment
Open

Is it possible to report Either<DecodeError, A> #59

aldex32 opened this issue Mar 31, 2022 · 1 comment

Comments

@aldex32
Copy link

aldex32 commented Mar 31, 2022

Hello,
I am using [email protected] and [email protected], but I cannot report an error for decode responses such as Either<DecodeError, A>. This is an example where I want to use the report instead of a raw error.

import * as D from 'io-ts/Decoder';
import { pipe } from 'fp-ts/function';
import { fold } from 'fp-ts/Either';

export function decode<A>(input: unknown, decoder: D.Decoder<unknown, A>): A {
    return pipe(
        decoder.decode(input),
        fold(
            (errors) => {
                throw new Error(JSON.stringify(errors)); // Here I want to use the reporter.
            },
            (value: A) => value,
        ),
    );
}

Are you planning to support the D.DecodeError for reporting?

@gillchristian
Copy link
Owner

Hi, I hadn't used io-ts/Decoder yet, only io-ts/index, so I did not come across the problem. And yes, this should be supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants