import { mapError } from "https://deno.land/x/domain_functions@v3.0.0/src/domain-functions.ts";
Creates a single domain function that will apply a transformation over the ErrorResult of a failed DomainFunction. When the given domain function succeeds, its result is returned without changes.
Examples
import { mdf, mapError } from 'domain-functions'
import { mdf, mapError } from 'domain-functions'
const increment = mdf(z.object({ id: z.number() }))(({ id }) => id + 1) const summarizeErrors = (result: ErrorData) => ({ errors: [{ message: 'Errors count: ' + result.errors.length }], inputErrors: [{ message: 'Input errors count: ' + result.inputErrors.length }], environmentErrors: [{ message: 'Environment errors count: ' + result.environmentErrors.length }], } as ErrorData)
const incrementWithErrorSummary = mapError(increment, summarizeErrors)
Parameters
dfn: DomainFunction<O>