Skip to content

Commit 0330389

Browse files
committed
Error status fixes
1 parent beeb449 commit 0330389

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/lib/client/superForm.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ export function superForm<
664664
}
665665

666666
function Form_resultStatus(defaultStatus: number) {
667-
if (defaultStatus >= 400) return defaultStatus;
667+
if (defaultStatus > 400) return defaultStatus;
668668
return (
669669
(typeof options.SPA === 'boolean' || typeof options.SPA === 'string'
670670
? undefined
@@ -1927,19 +1927,19 @@ export function superForm<
19271927
cancel();
19281928
});
19291929

1930-
function setErrorResult(error: unknown, data: { result: ActionResult }) {
1930+
function setErrorResult(error: unknown, data: { result: ActionResult }, status: number) {
19311931
data.result = {
19321932
type: 'error',
19331933
error,
1934-
status: Form_resultStatus(Math.max(result.status ?? 500, 400))
1934+
status: Form_resultStatus(status)
19351935
};
19361936
}
19371937

19381938
for (const event of formEvents.onResult) {
19391939
try {
19401940
await event(data);
19411941
} catch (error) {
1942-
setErrorResult(error, data);
1942+
setErrorResult(error, data, Math.max(result.status ?? 500, 400));
19431943
}
19441944
}
19451945

@@ -1970,7 +1970,7 @@ export function superForm<
19701970
try {
19711971
await event(data);
19721972
} catch (error) {
1973-
setErrorResult(error, data);
1973+
setErrorResult(error, data, Math.max(result.status ?? 500, 400));
19741974
}
19751975
}
19761976

@@ -2007,7 +2007,7 @@ export function superForm<
20072007
await Form_updateFromActionResult(result);
20082008
}
20092009
} else {
2010-
await triggerOnError(result, Math.max(result.status ?? 500, 500));
2010+
await triggerOnError(result, Math.max(result.status ?? 500, 400));
20112011
}
20122012
}
20132013
}

0 commit comments

Comments
 (0)