Skip to main content

AnalyticsError

Upgather Analytics


Upgather Analytics / AnalyticsError

Class: AnalyticsError

Custom error class for analytics-related errors.

Remarks

Extends Error to provide analytics-specific error information. This class adds HTTP status code and event ID context to errors, making it easier to diagnose and handle analytics-related issues.

All errors thrown by the analytics client will be instances of this class, allowing you to catch and handle them specifically.

Example

import { trackEvent, AnalyticsError } from '@upgather/analytics';

try {
await trackEvent({ ... });
} catch (err) {
if (err instanceof AnalyticsError) {
console.error(`Analytics error (${err.statusCode}): ${err.message}`);
if (err.eventId) {
console.error(`Failed event: ${err.eventId}`);
}
} else {
console.error('Unexpected error:', err);
}
}

Extends

  • Error

Constructors

new AnalyticsError()

new AnalyticsError(message, statusCode?, eventId?): AnalyticsError

Create a new AnalyticsError.

Parameters

message

string

Error message describing what went wrong

statusCode?

number

HTTP status code from the API response (if available)

eventId?

string

ID of the event that triggered the error (if available)

Returns

AnalyticsError

Overrides

Error.constructor

Properties

eventId?

optional eventId: string

Event ID that was being tracked when the error occurred.

Remarks

This helps identify which specific event triggered the error, useful for debugging and error reporting.


statusCode?

optional statusCode: number

HTTP status code returned from the API, if applicable.

Remarks

Common status codes:

  • 400: Bad Request (invalid input)
  • 401: Unauthorized (invalid or missing auth token)
  • 404: Not Found (invalid endpoint or resource)
  • 429: Too Many Requests (rate limited)
  • 500: Internal Server Error
  • 501: Not Implemented (endpoint not supported)
  • 503: Service Unavailable (backend unavailable)