@gateway.fm/gtw-dvf-client-js
Version:
DVF client js lib with gateway.fm rpc endpoints
19 lines (16 loc) • 476 B
JavaScript
const DVFError = require('../dvf/DVFError')
const defaultOptions = Object.freeze({
allowUnknown: true,
stripUnknown: true,
presence: 'required'
})
module.exports = (schema, options = defaultOptions) => errorType => errorProps => value => {
const { value: validated, error } = schema.validate(value, options)
if (error) {
throw new DVFError(
errorType,
{ ...errorProps, reason: error.message, details: error.details }
)
}
return validated
}