openmrs-esm-core

O3 Framework / reportError

Function: reportError()

reportError(err): void

Defined in: packages/framework/esm-error-handling/src/index.ts:43

Reports an error to the global error handler. The error will be displayed to the user as a toast notification. This function ensures the error is converted to an Error object if it isn’t already one.

The error is thrown asynchronously (via setTimeout) to ensure it’s caught by the global window.onerror handler.

Parameters

err

unknown

The error to report. Can be an Error object, string, or any other value.

Returns

void

Example

import { reportError } from '@openmrs/esm-framework';
try {
  await riskyOperation();
} catch (error) {
  reportError(error);
}