UNPKG

@volley/recognition-client-sdk

Version:

Recognition Service TypeScript/Node.js Client SDK

85 lines (74 loc) 2.36 kB
/** * SDK Error Classes * * Typed error classes that extend native Error with recognition-specific metadata */ import { ErrorTypeV1 } from '@recog/shared-types'; /** * Base class for all recognition SDK errors */ export class RecognitionError extends Error { public readonly errorType: ErrorTypeV1; public readonly timestamp: number; constructor(errorType: ErrorTypeV1, message: string) { super(message); this.name = 'RecognitionError'; this.errorType = errorType; this.timestamp = Date.now(); // Maintains proper stack trace for where error was thrown (only available on V8) if (Error.captureStackTrace) { Error.captureStackTrace(this, this.constructor); } } } /** * Connection error - thrown when WebSocket connection fails after all retry attempts */ export class ConnectionError extends RecognitionError { public readonly attempts: number; public readonly url: string; public readonly underlyingError?: Error; constructor(message: string, attempts: number, url: string, underlyingError?: Error) { super(ErrorTypeV1.CONNECTION_ERROR, message); this.name = 'ConnectionError'; this.attempts = attempts; this.url = url; if (underlyingError !== undefined) { this.underlyingError = underlyingError; } } } /** * Timeout error - thrown when operations exceed timeout limits */ export class TimeoutError extends RecognitionError { public readonly timeoutMs: number; public readonly operation: string; constructor(message: string, timeoutMs: number, operation: string) { super(ErrorTypeV1.TIMEOUT_ERROR, message); this.name = 'TimeoutError'; this.timeoutMs = timeoutMs; this.operation = operation; } } /** * Validation error - thrown when invalid configuration or input is provided */ export class ValidationError extends RecognitionError { public readonly field?: string; public readonly expected?: string; public readonly received?: string; constructor(message: string, field?: string, expected?: string, received?: string) { super(ErrorTypeV1.VALIDATION_ERROR, message); this.name = 'ValidationError'; if (field !== undefined) { this.field = field; } if (expected !== undefined) { this.expected = expected; } if (received !== undefined) { this.received = received; } } }