UNPKG

@yobta/validator

Version:
16 lines (15 loc) 592 B
import { handleUnknownError } from '../_internal/parseUnknownError/index.js'; import { rule } from '../rule/rule.js'; export const asyncSubmit = (submit) => rule(async (input, context) => { const { errors, event, field, path, pushError } = context; if ((event === null || event === void 0 ? void 0 : event.type) === 'submit' && !errors.length) { try { await submit(input, context); } catch (error) { const yobtaError = handleUnknownError({ error, field, path }); pushError(yobtaError); } } return input; });