@klever-one/web-sdk
Version:
Web SDK for integrating real-time room management and streaming functionality into web applications
75 lines (74 loc) • 2.46 kB
TypeScript
import { SDKError, SDKErrorCode, SDKErrorHandler } from '../types/sdk.types';
/**
* Centralized error handling utility for Klever One SDK
* Provides consistent error creation, logging, and handling across the SDK
*/
export declare class ErrorHandler {
private static errorHandlers;
private static isLoggingEnabled;
/**
* Register a global error handler
*/
static addErrorHandler(handler: SDKErrorHandler): void;
/**
* Remove a global error handler
*/
static removeErrorHandler(handler: SDKErrorHandler): void;
/**
* Enable or disable error logging
*/
static setLoggingEnabled(enabled: boolean): void;
/**
* Handle an error with logging and notification
*/
static handle(error: SDKError | Error | unknown): SDKError;
/**
* Create and handle a new SDK error
*/
static create(code: SDKErrorCode, message: string, context?: any): SDKError;
/**
* Normalize any error to SDKError
*/
private static normalizeError;
/**
* Log error with appropriate level based on error code
*/
private static logError;
}
/**
* Predefined error creators for common scenarios
*/
export declare const SDKErrors: {
connection: {
failed: (reason: string, context?: any) => SDKError;
timeout: (service: string, timeout: number) => SDKError;
websocketError: (error: Event, context?: any) => SDKError;
};
auth: {
invalidApiKey: (apiKey?: string) => SDKError;
unauthorized: (message: string) => SDKError;
};
streaming: {
connectionFailed: (url: string, reason?: string) => SDKError;
timeout: (url: string, timeout: number) => SDKError;
};
audio: {
microphoneAccessDenied: () => SDKError;
encodingError: (error: Error) => SDKError;
};
config: {
invalidConfiguration: (field: string, value: any) => SDKError;
missingParameter: (parameter: string) => SDKError;
};
network: {
networkError: (url: string, status?: number, statusText?: string) => SDKError;
};
};
/**
* Error boundary helper for React components
*/
export declare function withErrorBoundary<T>(fn: () => T, fallback?: T, errorHandler?: SDKErrorHandler): T | undefined;
/**
* Async error boundary helper
*/
export declare function withAsyncErrorBoundary<T>(fn: () => Promise<T>, fallback?: T, errorHandler?: SDKErrorHandler): Promise<T | undefined>;