Skip to main content

core.normalizeerrorevent

Home > @medplum/core > normalizeErrorEvent

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 Event with no error details (per the WHATWG WebSocket spec). - Node's ws library and Node's built-in (undici) WebSocket dispatch an ErrorEvent with both message and error. - Bun dispatches a plain Event with a message string but no error.

Signature:

export declare function normalizeErrorEvent(event: Event | ErrorEvent, target: unknown): ErrorEvent;

Parameters

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:

ErrorEvent

An ErrorEvent with a populated message and error.