Skip to content

Commit 73aa5da

Browse files
committed
chore(website): add action throwValidationErrors and throwServerError props sections
1 parent a5e687e commit 73aa5da

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

website/docs/execution/action-callbacks.md renamed to website/docs/execution/action-utils.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
---
22
sidebar_position: 3
3-
description: Action callbacks are a way to perform custom logic after the action is executed, on the server.
3+
description: Action utils is an object with useful properties and callbacks functions that you can use to customize the action execution flow.
44
---
55

6-
# Action callbacks
6+
# Action utils
77

8-
With action callbacks you can perform custom logic after the action is executed, on the server side. You can provide them to [`action`/`stateAction`](/docs/safe-action-client/instance-methods#action--stateaction) method as the second argument, after the server code function:
8+
Action utils is an object with some useful properties and callbacks passed as the second argument of the [`action`/`stateAction`](/docs/safe-action-client/instance-methods#action--stateaction) method.
9+
10+
## Throw errors when they occur
11+
12+
Starting from v7.4.0, you can now pass optional `throwServerError` and `throwValidationErrors` properties at the action level, if you want or need that behavior. Note that the `throwValidationErrors` property set at the action level has a higher priority than the one at the instance level, so if you set it to `false` while the one at the instance level is `true`, validation errors will **not** be thrown.
13+
14+
15+
## Callbacks
16+
17+
With action callbacks you can perform custom logic after the action is executed, on the server side. You can provide them to [`action`/`stateAction`](/docs/safe-action-client/instance-methods#action--stateaction) method in the second argument, after the server code function:
918

1019
```tsx
1120
import { actionClient } from "@/lib/safe-action";
@@ -27,8 +36,22 @@ const action = actionClient
2736
hasRedirected,
2837
hasNotFound,
2938
}) => {},
30-
onError: ({ error, ctx, metadata, clientInput, bindArgsClientInputs }) => {},
31-
onSettled: ({ result, ctx, metadata, clientInput, bindArgsClientInputs }) => {},
39+
onError: ({
40+
error,
41+
ctx,
42+
metadata,
43+
clientInput,
44+
bindArgsClientInputs
45+
}) => {},
46+
onSettled: ({
47+
result,
48+
ctx,
49+
metadata,
50+
clientInput,
51+
bindArgsClientInputs,
52+
hasRedirected,
53+
hasNotFound
54+
}) => {},
3255
});
3356
```
3457

website/docs/migrations/v6-to-v7.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ When working with i18n solutions, often you'll find implementations that require
149149

150150
### [Support action execution callbacks](https://github.com/TheEdoRan/next-safe-action/issues/162)
151151

152-
It's sometimes useful to be able to execute custom logic on the server side after an action succeeds or fails. Starting from version 7, next-safe-action allows you to pass action callbacks when defining an action. More information about this feature can be found [here](/docs/execution/action-callbacks).
152+
It's sometimes useful to be able to execute custom logic on the server side after an action succeeds or fails. Starting from version 7, next-safe-action allows you to pass action callbacks when defining an action. More information about this feature can be found [here](/docs/execution/action-utils#callbacks).
153153

154154
### [Support stateful actions using React `useActionState` hook](https://github.com/TheEdoRan/next-safe-action/issues/91)
155155

website/docs/safe-action-client/instance-methods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ action(serverCodeFn: ServerCodeFn, utils?: SafeActionUtils) => SafeActionFn
5151
stateAction(serverCodeFn: StateServerCodeFn, utils?: SafeActionUtils) => SafeStateActionFn
5252
```
5353

54-
`action`/`stateAction` is the final method in the list. It accepts a [`serverCodeFn`](#servercodefn) of type [`ServerCodeFn`](/docs/types#servercodefn)/[`StateServerCodeFn`](/docs/types#stateservercodefn) and an object with optional [action callbacks](/docs/execution/action-callbacks), and it returns a new safe action function of type [`SafeActionFn`](/docs/types#safeactionfn)/[`SafeStateActionFn`](/docs/types#safestateactionfn), which can be called from your components. When an action doesn't need input arguments, you can directly use this method without passing a schema to [`schema`](#schema) method.
54+
`action`/`stateAction` is the final method in the list. It accepts a [`serverCodeFn`](#servercodefn) of type [`ServerCodeFn`](/docs/types#servercodefn)/[`StateServerCodeFn`](/docs/types#stateservercodefn) and an optional object with [action utils](/docs/execution/action-utils), and it returns a new safe action function of type [`SafeActionFn`](/docs/types#safeactionfn)/[`SafeStateActionFn`](/docs/types#safestateactionfn), which can be called from your components. When an action doesn't need input arguments, you can directly use this method without passing a schema to [`schema`](#schema) method.
5555

5656
When the action is executed, all middleware functions in the chain will be called at runtime, in the order they were defined.
5757

website/docs/types.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ export type SafeActionUtils<
204204
CBAVE,
205205
Data,
206206
> = {
207+
throwServerError?: boolean;
208+
throwValidationErrors?: boolean;
207209
onSuccess?: (args: {
208210
data?: Data;
209211
clientInput: S extends Schema ? InferIn<S> : undefined;

0 commit comments

Comments
 (0)