/**
* Custom error classes for SkyFi MCP
*/
export class AppError extends Error {
public readonly statusCode: number;
public readonly isOperational: boolean;
public readonly code?: string;
public readonly details?: Record<string, unknown>;
constructor(
message: string,
statusCode: number = 500,
code?: string,
details?: Record<string, unknown>
) {
super(message);
this.statusCode = statusCode;
this.code = code;
this.details = details;
this.isOperational = true;
Error.captureStackTrace(this, this.constructor);
}
}
export class ValidationError extends AppError {
constructor(message: string, details?: Record<string, unknown>) {
super(message, 400, 'VALIDATION_ERROR', details);
}
}
export class AuthenticationError extends AppError {
constructor(message: string = 'Authentication failed') {
super(message, 401, 'AUTHENTICATION_ERROR');
}
}
export class AuthorizationError extends AppError {
constructor(message: string = 'Authorization failed') {
super(message, 403, 'AUTHORIZATION_ERROR');
}
}
export class NotFoundError extends AppError {
constructor(resource: string = 'Resource') {
super(`${resource} not found`, 404, 'NOT_FOUND');
}
}
export class ConflictError extends AppError {
constructor(message: string, details?: Record<string, unknown>) {
super(message, 409, 'CONFLICT_ERROR', details);
}
}
export class RateLimitError extends AppError {
constructor(message: string = 'Rate limit exceeded') {
super(message, 429, 'RATE_LIMIT_ERROR');
}
}
export class ExternalServiceError extends AppError {
constructor(
service: string,
message: string,
details?: Record<string, unknown>
) {
super(
`External service error: ${service} - ${message}`,
502,
'EXTERNAL_SERVICE_ERROR',
{ service, ...details }
);
}
}
export class DatabaseError extends AppError {
constructor(message: string, details?: Record<string, unknown>) {
super(message, 500, 'DATABASE_ERROR', details);
}
}