Skip to content

Expose error type for Unleash SDK error events #263

@gabrielduete

Description

@gabrielduete

Describe the feature request

Context

Currently, the Unleash SDK emits error messages without distinguishing their source.
For example:

Unleash: unable to send feature metrics TypeError: Failed to fetch

or

Unleash: unable to fetch feature toggles TypeError: Failed to fetch

However, when the SDK propagates the error event, the received object only contains the native exception (TypeError: Failed to fetch), without any indication of whether the failure happened when sending metrics or when fetching feature toggles.

Problem

In some scenarios, it’s important to distinguish between:

Failure while fetching toggles → critical → requires fallback (e.g., using CDN or local cache) and logging.

Failure while sending metrics → non-critical → can be ignored or logged at a lower priority.

Right now, there’s no reliable way to make this distinction using only the Error object.

Background

No response

Solution suggestions

Proposal

Add extra metadata to the emitted error event. For example:

emitter.emit('error', {
  type: 'metrics',
  error, // native error object
})

emitter.emit('error', {
  type: 'fetch-toggles',
  error,
})

Alternatively, the SDK could attach a property to the error object (error.context = 'metrics').

This would allow consumers to safely filter errors:

client.on('error', (err) => {
  if (err.type === 'fetch-toggles') {
    triggerFallback()
    captureMessage('Unleash flags fetch failed', { level: 'warning' })
  }
})

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions