Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/domain_functions/src/domain-functions.ts>mapError

Types and functions to make composition easy and safe
Latest
function mapError
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'

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

mapper: (element: ErrorData) => ErrorData | Promise<ErrorData>