From 5a52f44824ce685963caf3ebe1906ac26cc383d5 Mon Sep 17 00:00:00 2001 From: Edoardo Ranghieri Date: Wed, 4 Sep 2024 14:37:36 +0200 Subject: [PATCH] refactor: update action client server error handling functions --- apps/app/package.json | 2 +- apps/app/src/actions/safe-action.ts | 26 ++++++++++++-------------- bun.lockb | Bin 303840 -> 303840 bytes 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/app/package.json b/apps/app/package.json index df616446..b61853a9 100644 --- a/apps/app/package.json +++ b/apps/app/package.json @@ -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", diff --git a/apps/app/src/actions/safe-action.ts b/apps/app/src/actions/safe-action.ts index 3a32d4b0..7365baf8 100644 --- a/apps/app/src/actions/safe-action.ts +++ b/apps/app/src/actions/safe-action.ts @@ -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(), diff --git a/bun.lockb b/bun.lockb index e789afc221d006f1c910a6ab5e6e5834dc064970..de96de7468d5a75aca218af7830ca8508e4aa2e4 100755 GIT binary patch delta 153 zcmV;K0A~N-#S-Af5|Az+6M_8ApeWZ0B1rY+XM&W|891H5uTbwIK}}LBtV1PII6pVM@81(2~R+&P>1|)zxu*Jv>OFHjv+uyz8K^tdGI-Q zc(5#(BbmNIX2EUIqQDDdis#F?W6%iG#K4D*>H)Wn>H>hB134}*w-AT}Tj2vaE-<%l HX#{dPi@r!y delta 153 zcmaEGROrD`p$U2lj($QGOhLhZ&TdiqeHL5>+9rBy3%fOy>Lt$_SXHs+ZuHxBbaKlv zlV*!!+bxbUimEuYnVnoPL2=_Qaf!Woimi={!fk4rG?ja}!jG3IOq$kvr`KU>zkcC7 zl`g&147bGD#-)ljg{}Q(4^B96GJz|-N~yi~7322aS4<6anJx4Tw+nPIM?VC!@-kV9 FECKrEJi!0}