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
refactor: pass util props to handleReturnedServerError and handleServerErrorLog (#184)
This PR adds util props as the second argument of
`handleReturnedServerError` and `handleServerErrorLog` optional init
functions. Now you have access to `clientInput`, `bindArgsClientInputs`,
`ctx`, `metadata` and also `returnedError` (just for
`handleServerErrorLog`), which is the server error customized by
`handleReturnedServerError` function.
re #177
Copy file name to clipboardexpand all lines: website/docs/safe-action-client/initialization-options.md
+13-6
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ description: You can initialize a safe action client with these options.
7
7
8
8
## `handleReturnedServerError?`
9
9
10
-
You can provide this optional function to the safe action client. It is used to customize the server error returned to the client, if one occurs during action's server execution. This includes errors thrown by the action server code, and errors thrown by the middleware.
10
+
You can provide this optional function to the safe action client. It is used to customize the server error returned to the client, if one occurs during action's server execution. This includes errors thrown by the action server code, and errors thrown by the middleware. You also have access to useful properties via the `utils` object, which is the second argument of the function.
11
11
12
12
Here's a simple example, changing the default message for every error thrown on the server:
13
13
@@ -16,7 +16,10 @@ import { createSafeActionClient } from "next-safe-action";
@@ -66,7 +69,7 @@ Note that the return type of this function will determine the type of the server
66
69
67
70
## `handleServerErrorLog?`
68
71
69
-
You can provide this optional function to the safe action client. This is used to define how errors should be logged when one occurs while the server is executing an action. This includes errors thrown by the action server code, and errors thrown by the middleware. Here you get as argument the **original error object**, not a message customized by `handleReturnedServerError`, if provided.
72
+
You can provide this optional function to the safe action client. This is used to define how errors should be logged when one occurs while the server is executing an action. This includes errors thrown by the action server code, and errors thrown by the middleware. Here you get as the first argument the **original error object**, not the one customized by `handleReturnedServerError`, if provided. Though, you can access the `returnedError` and other useful properties inside the `utils` object, which is the second argument.
70
73
71
74
Here's a simple example, logging error to the console while also reporting it to an error handling system:
72
75
@@ -75,12 +78,16 @@ import { createSafeActionClient } from "next-safe-action";
0 commit comments