/** * Feature Not Enabled Error * * Error thrown when attempting to use a feature that is not enabled * * @module errors/FeatureNotEnabledError */ import { OrbisError, OrbisErrorCode } from './OrbisError'; import { Feature } from '../types/Feature'; /** * FeatureNotEnabledError class * * Thrown when attempting to use a feature that has not been enabled in the SDK configuration. */ export class FeatureNotEnabledError extends OrbisError { /** Feature that is not enabled */ public readonly feature: Feature; /** * Create a FeatureNotEnabledError * * @param feature - Feature that is not enabled * @param additionalContext - Additional context */ constructor(feature: Feature, additionalContext?: Record) { super( `Feature '${feature}' is not enabled. Enable it in the SDK configuration.`, OrbisErrorCode.FEATURE_NOT_ENABLED, undefined, { feature, ...additionalContext, } ); this.name = 'FeatureNotEnabledError'; this.feature = feature; // Maintains proper stack trace for where our error was thrown (only available on V8) if (Error.captureStackTrace) { Error.captureStackTrace(this, FeatureNotEnabledError); } } /** * Create a FeatureNotEnabledError with help message * * @param feature - Feature that is not enabled * @param helpMessage - Additional help message * @returns FeatureNotEnabledError instance */ static withHelp( feature: Feature, helpMessage: string ): FeatureNotEnabledError { const error = new FeatureNotEnabledError(feature, { helpMessage }); error.message += `\n${helpMessage}`; return error; } /** * Convert error to JSON */ toJSON(): Record { return { ...super.toJSON(), feature: this.feature, }; } }