@tryloop/oats
Version:
🌾 OATS - OpenAPI TypeScript Sync. The missing link between your OpenAPI specs and TypeScript applications. Automatically watch, generate, and sync TypeScript clients from your API definitions.
172 lines • 5.32 kB
TypeScript
/**
* Custom Error Classes for OATS
*
* This module defines a hierarchy of error classes for better error handling
* and user-friendly error messages throughout the application.
*
* @module @oatsjs/errors
*/
/**
* Base error class for all OATS errors
*/
export declare abstract class OatsError extends Error {
/**
* Error code for programmatic handling
*/
readonly code: string;
/**
* Additional context about the error
*/
readonly context?: Record<string, unknown>;
/**
* Whether this error is recoverable
*/
readonly recoverable: boolean;
/**
* Timestamp when the error occurred
*/
readonly timestamp: Date;
constructor(message: string, code: string, recoverable?: boolean, context?: Record<string, unknown>);
/**
* Returns a user-friendly error message
*/
getUserMessage(): string;
/**
* Returns error details for logging
*/
getDetails(): Record<string, unknown>;
}
/**
* Configuration-related errors
*/
export declare class ConfigError extends OatsError {
constructor(message: string, context?: Record<string, unknown>);
}
/**
* Configuration validation error
*/
export declare class ConfigValidationError extends ConfigError {
readonly validationErrors: Array<{
path: string;
message: string;
}>;
constructor(message: string, validationErrors: Array<{
path: string;
message: string;
}>, context?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Service-related errors
*/
export declare class ServiceError extends OatsError {
readonly service: string;
constructor(message: string, service: string, code?: string, recoverable?: boolean, context?: Record<string, unknown>);
}
/**
* Service start error
*/
export declare class ServiceStartError extends ServiceError {
readonly exitCode?: number;
readonly stderr?: string;
constructor(service: string, message: string, exitCode?: number, stderr?: string, context?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* File system errors
*/
export declare class FileSystemError extends OatsError {
readonly path: string;
readonly operation: string;
constructor(message: string, path: string, operation: string, recoverable?: boolean, context?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* API specification errors
*/
export declare class ApiSpecError extends OatsError {
readonly specPath: string;
constructor(message: string, specPath: string, recoverable?: boolean, context?: Record<string, unknown>);
}
/**
* Generator errors
*/
export declare class GeneratorError extends OatsError {
readonly generator: string;
readonly phase: 'generate' | 'build' | 'link';
constructor(message: string, generator: string, phase: 'generate' | 'build' | 'link', recoverable?: boolean, context?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Network-related errors
*/
export declare class NetworkError extends OatsError {
readonly url?: string;
readonly statusCode?: number;
constructor(message: string, url?: string, statusCode?: number, context?: Record<string, unknown>);
}
/**
* Dependency errors
*/
export declare class DependencyError extends OatsError {
readonly dependency: string;
readonly requiredVersion?: string;
readonly installedVersion?: string;
constructor(message: string, dependency: string, requiredVersion?: string, installedVersion?: string, context?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Command execution errors
*/
export declare class CommandError extends OatsError {
readonly command: string;
readonly exitCode: number;
readonly stdout?: string;
readonly stderr?: string;
constructor(message: string, command: string, exitCode: number, stdout?: string, stderr?: string, context?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Timeout errors
*/
export declare class TimeoutError extends OatsError {
readonly operation: string;
readonly timeoutMs: number;
constructor(operation: string, timeoutMs: number, context?: Record<string, unknown>);
}
/**
* User cancellation error
*/
export declare class UserCancelledError extends OatsError {
constructor(operation: string, context?: Record<string, unknown>);
}
/**
* Creates an error with a suggestion for fixing it
*/
export declare class ErrorWithSuggestion extends OatsError {
readonly suggestion: string;
constructor(message: string, code: string, suggestion: string, recoverable?: boolean, context?: Record<string, unknown>);
getUserMessage(): string;
}
/**
* Error handler utility
*/
export declare class ErrorHandler {
/**
* Handles an error and returns a user-friendly message
*/
static handle(error: unknown): string;
/**
* Logs error details for debugging
*/
static log(error: unknown, logger?: (message: string) => void): void;
/**
* Determines if an error is recoverable
*/
static isRecoverable(error: unknown): boolean;
/**
* Wraps an async function with error handling
*/
static wrap<T>(fn: () => Promise<T>, context: string): Promise<T | undefined>;
}
//# sourceMappingURL=index.d.ts.map