Custom error message
A decoder that always fails when executed
This example uses expected to create the error message.
const base64_decoder = Decode.andThen(str => {
try {
return Decode.succeed(atob(str));
} catch {
return Decode.fail(expected('a valid base64 string', str));
}
}, Decode.string);
decode(base64_decoder, 'SGVsbG8sIFdvcmxkIQ==') === 'Hello, World!'
decode(base64_decoder, 'invalid$') // Throws
Generated using TypeDoc
Make a decoder that never succeeds and fails with the given message. This is mostly useful for building custom decoders with
andThen
.