You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(client): normalize both server error envelopes so err.code / err.fields mean one thing (#3918 follow-up) (#3927)
Two envelopes are in play and they disagree about where the semantic code and
the per-field list live:
@objectstack/rest, flat:
{ error, code: 'VALIDATION_FAILED', fields: [...] }
runtime dispatcher, wrapped:
{ success: false, error: { message, code: 400,
details: { code: 'VALIDATION_FAILED', fields: [...] } } }
`error.code` in the WRAPPED form is the HTTP status, not a semantic code. The
client read it straight through, so `err.code` was the number 400 where the
flat envelope gave 'VALIDATION_FAILED' — the branch our own docs teach
(`if (err.code === 'VALIDATION_FAILED') err.fields.forEach(…)`) never matched
on a dispatcher-served surface, and the field list #3918 put on the wire for
those routes was unreachable at `err.details.error.details.fields`.
Normalized at the throw site:
- `err.code` is always the semantic STRING — flat `code`, else wrapped
`error.details.code`, else a string `error.code`. A numeric value is never
reported as a code; the status stays on `err.httpStatus`.
- `err.fields` is the per-field list from either envelope, left UNSET (not [])
when the server sent none, so `if (err.fields)` tests "field-anchored".
- `err.details` prefers a top-level `details` (unchanged), then the wrapped
envelope's own `details`, then the whole body — the flat envelope is
unaffected.
Nothing in this repo read `err.code` as a number, but a consumer that branched
on `err.code === 400` should move to `err.httpStatus === 400`.
Docs updated in the same change: `api/client-sdk.mdx` gains the `fields`
contract and the code-vs-status rule, and `api/error-catalog.mdx`'s
client-side section is corrected — it claimed the SDK attaches no field list
while its own example called `apiError.fieldErrors`, which could never have
worked.
Covered by 8 cases in client.test.ts; the 4 targeting the wrapped envelope
fail on the pre-fix source.
0 commit comments