core.normalizeerrorevent | Medplum
normalizeErrorEvent() function
Normalizes the various error event shapes dispatched by different WebSocket implementations into a single ErrorEvent carrying a real Error, so downstream listeners always get message and error regardless of the underlying implementation:
- Browsers dispatch a plain
Eventwith no error details (per the WHATWG WebSocket spec). - Node's
wslibrary and Node's built-in (undici)WebSocketdispatch anErrorEventwith bothmessageanderror. - Bun dispatches a plain
Eventwith amessagestring but noerror.
Signature:
export declare function normalizeErrorEvent(event: Event | ErrorEvent, target: unknown): ErrorEvent;
Parameters [](/content/docs/sdk/core.normalizeerrorevent#parameters "Direct link to Parameters"/index.html)
| Parameter | Type | Description |
|---|---|---|
| event | Event | ErrorEvent | The error event as dispatched by the underlying WebSocket. |
| target | unknown | The ReconnectingWebSocket instance the normalized event is dispatched from. |
Returns:
An ErrorEvent with a populated message and `error.