Skip to content

Commit

Permalink
refactor: update action client server error handling functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEdoRan committed Sep 4, 2024
1 parent 5f2807c commit 5a52f44
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"geist": "^1.3.1",
"next": "14.2.7",
"next-international": "^1.2.4",
"next-safe-action": "^7.8.1",
"next-safe-action": "^7.9.0",
"next-themes": "^0.3.0",
"nuqs": "^1.18.0",
"react": "^18.3.1",
Expand Down
26 changes: 12 additions & 14 deletions apps/app/src/actions/safe-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,22 @@ import {
import { headers } from "next/headers";
import { z } from "zod";

export const actionClient = createSafeActionClient({
handleReturnedServerError(e) {
if (e instanceof Error) {
return e.message;
}
const handleServerError = (e: Error) => {
console.error("Action error:", e.message);

return DEFAULT_SERVER_ERROR_MESSAGE;
},
if (e instanceof Error) {
return e.message;
}

return DEFAULT_SERVER_ERROR_MESSAGE;
};

export const actionClient = createSafeActionClient({
handleServerError,
});

export const actionClientWithMeta = createSafeActionClient({
handleReturnedServerError(e) {
if (e instanceof Error) {
return e.message;
}

return DEFAULT_SERVER_ERROR_MESSAGE;
},
handleServerError,
defineMetadataSchema() {
return z.object({
name: z.string(),
Expand Down
Binary file modified bun.lockb
Binary file not shown.

0 comments on commit 5a52f44

Please sign in to comment.