murmuraba
Version:
Real-time audio noise reduction with advanced chunked processing for web applications
71 lines • 4.45 kB
TypeScript
/**
* Centralized Error Handling Utility
* Eliminates duplicate error creation patterns across the codebase
*/
export declare enum ErrorType {
AUDIO_CONTEXT = "AUDIO_CONTEXT_ERROR",
MEDIA_RECORDER = "MEDIA_RECORDER_ERROR",
WASM_MODULE = "WASM_MODULE_ERROR",
AUDIO_PROCESSING = "AUDIO_PROCESSING_ERROR",
VALIDATION = "VALIDATION_ERROR",
INITIALIZATION = "INITIALIZATION_ERROR",
NETWORK = "NETWORK_ERROR",
FILE_SYSTEM = "FILE_SYSTEM_ERROR",
PERMISSION = "PERMISSION_ERROR",
UNSUPPORTED = "UNSUPPORTED_ERROR"
}
export declare class MurmurabaError extends Error {
readonly type: ErrorType;
readonly code: string;
readonly details?: Record<string, any>;
readonly timestamp: number;
constructor(type: ErrorType, message: string, code?: string, details?: Record<string, any>);
toJSON(): {
name: string;
type: ErrorType;
code: string;
message: string;
details: Record<string, any> | undefined;
timestamp: number;
stack: string | undefined;
};
}
export declare class ErrorFactory {
static audioContextNotSupported(details?: Record<string, any>): MurmurabaError;
static audioContextSuspended(details?: Record<string, any>): MurmurabaError;
static audioContextCreationFailed(originalError?: Error, details?: Record<string, any>): MurmurabaError;
static mediaRecorderNotSupported(details?: Record<string, any>): MurmurabaError;
static mediaRecorderStartFailed(originalError?: Error, details?: Record<string, any>): MurmurabaError;
static mediaRecorderInvalidState(currentState: string, expectedState: string, details?: Record<string, any>): MurmurabaError;
static wasmModuleNotLoaded(details?: Record<string, any>): MurmurabaError;
static wasmModuleLoadFailed(originalError?: Error, details?: Record<string, any>): MurmurabaError;
static wasmProcessingFailed(originalError?: Error, details?: Record<string, any>): MurmurabaError;
static audioProcessingFailed(stage: string, originalError?: Error, details?: Record<string, any>): MurmurabaError;
static invalidAudioFormat(expectedFormat: string, receivedFormat: string, details?: Record<string, any>): MurmurabaError;
static audioBufferTooSmall(minSize: number, actualSize: number, details?: Record<string, any>): MurmurabaError;
static invalidParameter(paramName: string, expectedType: string, receivedValue: any, details?: Record<string, any>): MurmurabaError;
static parameterOutOfRange(paramName: string, value: number, min: number, max: number, details?: Record<string, any>): MurmurabaError;
static requiredParameterMissing(paramName: string, details?: Record<string, any>): MurmurabaError;
static initializationFailed(component: string, originalError?: Error, details?: Record<string, any>): MurmurabaError;
static componentAlreadyInitialized(component: string, details?: Record<string, any>): MurmurabaError;
static microphonePermissionDenied(details?: Record<string, any>): MurmurabaError;
static audioPermissionNotGranted(details?: Record<string, any>): MurmurabaError;
static featureNotSupported(feature: string, details?: Record<string, any>): MurmurabaError;
static browserNotSupported(requiredFeatures: string[], details?: Record<string, any>): MurmurabaError;
static wrapError(originalError: Error, type: ErrorType, additionalMessage?: string, details?: Record<string, any>): MurmurabaError;
}
export declare class ErrorHandler {
private static errorCallbacks;
private static globalErrorCallback?;
static onError(type: ErrorType, callback: (error: MurmurabaError) => void): void;
static onAnyError(callback: (error: MurmurabaError) => void): void;
static handle(error: MurmurabaError): MurmurabaError;
static create(type: ErrorType, message: string, code?: string, details?: Record<string, any>): MurmurabaError;
static clearCallbacks(): void;
}
export declare const throwIf: (condition: boolean, errorFactory: () => MurmurabaError) => void;
export declare const throwIfNot: (condition: boolean, errorFactory: () => MurmurabaError) => void;
export declare const wrapAsync: <T>(asyncFn: () => Promise<T>, errorFactory: (error: Error) => MurmurabaError) => Promise<T>;
export declare const wrapSync: <T>(syncFn: () => T, errorFactory: (error: Error) => MurmurabaError) => T;
export { MurmurabaError as default };
//# sourceMappingURL=error-handler.d.ts.map