You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`params`: params which were passed to the [_Mutation_](/api/primitives/mutation)
50
+
-`headers`: raw response headers (available for HTTP errors and contract/validation errors where the response was received, not available for network errors)
51
+
41
52
-`status.expected`: `number` or `Array<number>` of expected HTTP status codes, if the response status code is not in the list, the mutation will be treated as failed
42
53
43
54
-`concurrency?`: concurrency settings for the [_Mutation_](/api/primitives/mutation)
@@ -50,3 +61,77 @@ Config fields:
50
61
:::
51
62
52
63
-`abort?`: [_Event_](https://effector.dev/en/api/effector/event/) after calling which all in-flight requests will be aborted
64
+
65
+
## Examples
66
+
67
+
### Error mapping
68
+
69
+
You can transform errors before they are passed to the [_Mutation_](/api/primitives/mutation) using `mapError`:
### `createMutation({ effect, contract?, mapError: Function })` <Badgetype="tip"text="since v0.14" />
76
+
77
+
Creates [_Mutation_](/api/primitives/mutation) based on given [_Effect_](https://effector.dev/en/api/effector/effect/). When the [_Mutation_](/api/primitives/mutation) fails, the error is passed to `mapError` callback, and the result of the callback will be treated as the error of the [_Mutation_](/api/primitives/mutation).
78
+
79
+
```ts
80
+
const loginMutation =createMutation({
81
+
effect: loginFx,
82
+
contract: loginContract,
83
+
mapError({ error, params }) {
84
+
// Transform any error into a user-friendly message
Creates [_Mutation_](/api/primitives/mutation) based on given [_Effect_](https://effector.dev/en/api/effector/effect/). When the [_Mutation_](/api/primitives/mutation) fails, the error is passed to `mapError.fn` callback as well as original parameters of the [_Mutation_](/api/primitives/mutation) and current value of `mapError.source`[_Store_](https://effector.dev/en/api/effector/store/), result of the callback will be treated as the error of the [_Mutation_](/api/primitives/mutation).
-`params`: the parameters that were passed to the [_Query_](/api/primitives/query)
178
+
-`params`: the parameters that were passed to the [_Query_](/api/primitives/query) or [_Mutation_](/api/primitives/mutation)
179
179
-`headers`: raw response headers (available for HTTP errors and contract/validation errors where the response was received, not available for network errors)
180
180
181
+
The same `mapError` option is available for [_Mutations_](/api/primitives/mutation):
**Basic factories** are used to create _Remote Operations_ with a more control of data-flow in user-land. In this case, the user-land code have to describe **request-response cycle** and **response parsing** stages. Other stages could be handled by the library, but it is not required for **basic factories**.
0 commit comments