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`.
This commit is contained in:
@@ -94,7 +94,7 @@ export const buildFormStateHandler: ServerFunction<
|
||||
}
|
||||
|
||||
if (err.message === 'Unauthorized') {
|
||||
return null
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
|
||||
return formatErrors(err)
|
||||
|
||||
Reference in New Issue
Block a user