> For the complete documentation index, see [llms.txt](https://demystifyfp.gitbook.io/fstoolkit-errorhandling/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://demystifyfp.gitbook.io/fstoolkit-errorhandling/fstoolkit.errorhandling/index-1/maperror.md).

# mapError

Namespace: `FsToolkit.ErrorHandling`

`mapError` takes an async validation and a normal function and returns a new async validation value based on the input error value and the function

## Function Signature

```fsharp
('errorInput -> 'errorOutput) -> AsyncValidation<'ok, 'errorInput> 
    -> AsyncValidation<'ok, 'errorOutput>
```

## Examples

Take the following functions for example

```fsharp
// string -> int
let getErrorCode (message: string) =
    match message with
    | "bad things happened" -> 1
    | _ -> 0
```

### Example 1

```fsharp
let result =
    AsyncValidation.ok "all good" // AsyncValidation<string, string>
    |> AsyncValidation.mapError getErrorCode // AsyncValidation<string, int>

// async { Ok "all good" }
```

### Example 2

```fsharp
let result =
    AsyncValidation.error "bad things happened" // AsyncValidation<string, string>
    |> AsyncValidation.mapError getErrorCode // AsyncValidation<string, int>

// async { Error [1] }
```
