Skip to content

Commit

Permalink
fix: pass error handler
Browse files Browse the repository at this point in the history
  • Loading branch information
MiroslavPetrik committed Feb 5, 2024
1 parent 1624dd3 commit 76e2f06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export const signIn = authAction
return t("verificationEmail.success");
});

export const signUp = authAction
import { formAction } from "react-fomr-action";

export const signUp = formAction
.input(
z
.object({
Expand All @@ -88,7 +90,7 @@ export const signUp = authAction

await db.signUp({ email, password });

return t("signUp.success");
return "We've sent you an email!";
});
```

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-form-action",
"version": "0.4.0",
"version": "0.4.1",
"description": "State management helpers for the react form actions.",
"repository": {
"type": "git",
Expand Down
12 changes: 7 additions & 5 deletions src/formAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ function formActionBuilder<
if (schema === emptyInput) {
return formActionBuilder<T, Err, Context & NewContext>(
newInput,
middleware
middleware,
processError
);
} else if (schema._def.effect) {
throw new Error(
Expand All @@ -228,10 +229,11 @@ function formActionBuilder<
use<NewContext extends Record<string, unknown>>(
newMiddleware: ({ ctx }: { ctx: Context }) => Promise<NewContext>
) {
return formActionBuilder<Schema, Err, Context & NewContext>(schema, [
...middleware,
newMiddleware,
]);
return formActionBuilder<Schema, Err, Context & NewContext>(
schema,
[...middleware, newMiddleware],
processError
);
},
error<Err>(
processError: (params: { error: unknown; ctx: Context }) => Err
Expand Down

0 comments on commit 76e2f06

Please sign in to comment.