Namespace: FsToolkit.ErrorHandling
Function Signature:
('errorInput -> 'errorOutput)
-> CancellableTaskValidation<'ok, 'errorInput>
-> CancellableTaskValidation<'ok, 'errorOutput>Applies a mapping function to each error in the error list inside a CancellableTaskValidation. If the computation is Ok, the mapping function is not called and the value is propagated unchanged.
Note: mapError applies the function element-wise to each error in the list. To transform the entire error list at once, use mapErrors.
Wrapping low-level errors in a domain error type:
let validateUser (input: UserInput) : CancellableTaskValidation<User, AppError> =
fetchAndValidateUser input
|> CancellableTaskValidation.mapError AppError.ValidationErrorConverting errors to strings for display:
let getValidationMessages (userId: UserId) : CancellableTaskValidation<User, string> =
fetchUser userId
|> CancellableTaskValidation.mapError (fun (err: ValidationError) -> err.Message)Lifting errors from one domain to another at a boundary:
let createOrder (request: OrderRequest) : CancellableTaskValidation<Order, OrderServiceError> =
validateOrderRequest request
|> CancellableTaskValidation.mapError OrderServiceError.fromValidationError