Changelog - 2026-07-20
fromError - Rehydrate a Server Error on the Client
New APIIn one line. fromError({ error }) turns the JSON payload AppErrorMiddleware sends into a live ApplicationError, so one catch block handles a server failure and a locally thrown one alike.
What changed
fromError({ error })rebuilds anApplicationErrorfrom the payloadAppErrorMiddlewareemits.TResponsedErrornames the response shape in plain TypeScript, so a browser can import it and drop its own partial copy of the type.- Every field of
TResponsedErroris optional. A client can parse what a gateway, a proxy, or an older server actually sent. - A malformed response still yields a usable error. An HTML 502 or an empty body produces an
ApplicationErrorwithMessageCode.DEFAULTand status400.
ts
import { fromError, isApplicationError } from '@venizia/ignis-inversion';
try {
const response = await fetch('/reservations', { method: 'POST', body });
if (!response.ok) {
const { error } = await response.json(); // `error` is the rootKey, if configured
throw fromError({ error });
}
} catch (error) {
if (isApplicationError(error)) {
showToast(translate(error.normalized.code, error.normalized.args));
}
}Who is affected
- Existing clients. Nothing to do. Reading
error.normalized.codestays correct. - Clients with a hand-rolled wire type or response-to-error mapping. Replace it with
fromErrorand drop the local declaration.
Details
- Use
isApplicationError()as the guard in a browser, notinstanceof ApplicationError. The client bundles its own copy of the class, soinstanceoffails across the package boundary. - A body read straight from
response.json()is a plain object, soisApplicationError()returnsfalseon it untilfromErrorhas run. messagebecomesnormalized.textonly whennormalizedis missing.requestIdlands inextra.requestId.detailsis dropped.
See also
- Error - the full error layer, including the response shape
- Error Module Redesign - where
{ text, code, args }came from