File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
packages/next-safe-action/src Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,9 @@ export function actionBuilder<
73
73
const parsedInputDatas : any [ ] = [ ] ;
74
74
const frameworkErrorHandler = new FrameworkErrorHandler ( ) ;
75
75
76
+ // Track if server error has been handled.
77
+ let serverErrorHandled = false ;
78
+
76
79
if ( withState ) {
77
80
// Previous state is placed between bind args and main arg inputs, so it's always at the index of
78
81
// the bind args schemas + 1. Get it and remove it from the client inputs array.
@@ -242,6 +245,11 @@ export function actionBuilder<
242
245
middlewareResult . bindArgsParsedInputs = parsedInputDatas . slice ( 0 , - 1 ) ;
243
246
}
244
247
} catch ( e : unknown ) {
248
+ // Only handle server errors once. If already handled, rethrow to bubble up.
249
+ if ( serverErrorHandled ) {
250
+ throw e ;
251
+ }
252
+
245
253
// If error is `ActionServerValidationError`, return `validationErrors` as if schema validation would fail.
246
254
if ( e instanceof ActionServerValidationError ) {
247
255
const ve = e . validationErrors as ValidationErrors < IS > ;
@@ -256,6 +264,9 @@ export function actionBuilder<
256
264
} )
257
265
) ;
258
266
} else {
267
+ // Mark that we're handling the server error to prevent multiple calls.
268
+ serverErrorHandled = true ;
269
+
259
270
// If error is not an instance of Error, wrap it in an Error object with
260
271
// the default message.
261
272
const error = isError ( e ) ? e : new Error ( DEFAULT_SERVER_ERROR_MESSAGE ) ;
You can’t perform that action at this time.
0 commit comments