Skip to content

Commit 06ef798

Browse files
authored
fix(ui): ensure buildFormStateHandler throws error instead of returning null for unauthorized requests (#13123)
### What? Prevents `buildFormStateHandler` from returning `null` in unauthorized scenarios by throwing an explicit `Error` instead. ### Why? The `BuildFormStateResult` type does not include `null`, but previously the handler returned `null` when access was unauthorized. This caused runtime type mismatches and forced client-side workarounds (e.g. guarding destructures). By always throwing instead of returning `null`, the client code can safely assume a valid result or catch errors. <img width="1772" height="723" alt="Screenshot_2025-07-10_185618" src="https://github.com/user-attachments/assets/d65344e3-a2cb-4ec5-91bf-a353b5b7dd14" /> ### How? - Replaced the `return null` with `throw new Error('Unauthorized')` in `buildFormStateHandler`. - Client code no longer needs to handle `null` responses from `getFormState`.
1 parent 5695d22 commit 06ef798

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/ui/src/utilities/buildFormState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const buildFormStateHandler: ServerFunction<
9494
}
9595

9696
if (err.message === 'Unauthorized') {
97-
return null
97+
throw new Error('Unauthorized')
9898
}
9999

100100
return formatErrors(err)

0 commit comments

Comments
 (0)