gcanti / io-ts

Runtime type system for IO decoding/encoding
https://gcanti.github.io/io-ts/
MIT License
6.71k stars 329 forks source link

Providing a way to replace the failure implementation #703

Open shau-kote opened 1 year ago

shau-kote commented 1 year ago

Description

The given PR provides a way to replace the failure implementation used by the built-in codecs, like, t.string etc.

Goal

We want to use the current full-featured validation in the dev environment, but in the production we want to just log errors and go ahead "as is".

So the idea is to have an option to change the validation behaviour with a code like this.

import {success, setFailureImplementation} from ''

if (process.env.NODE_ENV !== 'development') {
  setFailureImplementation(value, context, message) => { 
    Logger.logError(context, message)
    return success(value)
  }
}

Please feel free to add your feedback, I'll do my best to fine-tune my PR>