Skip to content

Report Custom Errors

The Browser RUM SDK automatically collects unhandled frontend exceptions. For exceptions that have already been caught by business code but still require monitoring, use addError(error, context?) to report them proactively.

Parameters

Parameter Type Required Description
error Unknown Yes It is recommended to pass the original Error object to preserve the message and stack.
context Object No Business fields when the error occurs, such as page state, API name, or retry count.

NPM Example

import { datafluxRum } from "@cloudcare/browser-rum"

async function submit() {
  try {
    await submitOrder()
  } catch (error) {
    datafluxRum.addError(error, {
      operation: "submit_order",
      retry_count: 1
    })
  }
}

CDN Example

fetch("/api/orders").catch(function (error) {
  window.DATAFLUX_RUM &&
    window.DATAFLUX_RUM.addError(error, {
      operation: "submit_order"
    })
})
fetch("/api/orders").catch(function (error) {
  window.DATAFLUX_RUM.onReady(function () {
    window.DATAFLUX_RUM.addError(error, {
      operation: "submit_order"
    })
  })
})

Notes

  1. Pass the original Error object whenever possible; do not pass only error.message.
  2. Do not include sensitive data such as passwords, tokens, or full request bodies in the Context.
  3. If the same exception is both automatically collected by the SDK and reported via addError(), two Error data entries will be created. Only call this API for exceptions that have been handled or proactively identified by the business logic.

Validation

After triggering the exception, go to the Error Explorer of the corresponding web application, filter by the operation field with the value submit_order, and check the error message, stack, and custom Context.

Feedback

Is this page helpful?