UNPKG

webssh2-server

Version:

A Websocket to SSH2 gateway using xterm.js, socket.io, ssh2

103 lines (102 loc) 3.01 kB
import type { Result } from '../types/result.js'; /** * Standard error types */ export declare enum ErrorType { Validation = "validation", Authentication = "authentication", Network = "network", Timeout = "timeout", Permission = "permission", Configuration = "configuration", NotFound = "not-found", Conflict = "conflict", RateLimit = "rate-limit", Internal = "internal", Unknown = "unknown" } /** * Standard error with type information */ export interface TypedError extends Error { readonly type: ErrorType; readonly code?: string; readonly statusCode?: number; readonly details?: unknown; readonly recoverable?: boolean; } /** * Create a typed error */ export declare function createTypedError(message: string, type?: ErrorType, options?: { code?: string; statusCode?: number; details?: unknown; recoverable?: boolean; }): TypedError; /** * Extract error message from unknown error */ export declare function extractErrorMessage(error: unknown): string; /** * Extract error code from unknown error */ export declare function extractErrorCode(error: unknown): string | undefined; /** * Classify error type from error object */ export declare function classifyErrorType(error: unknown): ErrorType; /** * Convert error type to HTTP status code */ export declare function errorTypeToStatusCode(type: ErrorType): number; /** * Convert SSH error type to standard error type */ export declare function sshErrorTypeToErrorType(sshType: string): ErrorType; /** * Wrap function execution in try-catch and return Result */ export declare function tryExecute<T>(fn: () => T, errorType?: ErrorType): Result<T, TypedError>; /** * Wrap async function execution in try-catch and return Result */ export declare function tryExecuteAsync<T>(fn: () => Promise<T>, errorType?: ErrorType): Promise<Result<T, TypedError>>; /** * Log error with context */ export declare function logError(context: string, error: unknown, details?: Record<string, unknown>): void; /** * Create error response object */ export interface ErrorResponse { readonly error: { readonly message: string; readonly type: ErrorType; readonly code?: string; readonly statusCode: number; readonly timestamp: Date; readonly details?: unknown; }; } /** * Format error for API response */ export declare function formatErrorResponse(error: unknown, includeDetails?: boolean): ErrorResponse; /** * Error recovery strategies */ export interface RecoveryStrategy { readonly maxAttempts: number; readonly delay: number; readonly backoff?: number; readonly shouldRetry: (error: unknown, attempt: number) => boolean; } /** * Default recovery strategy */ export declare const defaultRecoveryStrategy: RecoveryStrategy; /** * Execute with retry on failure */ export declare function executeWithRetry<T>(fn: () => Promise<T>, strategy?: RecoveryStrategy): Promise<Result<T, TypedError>>;