Skip to main content
Module

x/domain_functions/mod.ts>mapError

Decouple your business logic from your framework. With first-class type inference from end to end.
Latest
function mapError
import { mapError } from "https://deno.land/x/domain_functions@v2.6.0/mod.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>