@paykit-sdk/core
Version:
The Payment Toolkit for Typescript
134 lines (132 loc) • 4.14 kB
text/typescript
/**
* Base PayKit error class
*/
declare class PayKitError extends Error {
readonly code: string;
readonly statusCode: number;
readonly provider?: string;
readonly method?: string;
readonly context?: Record<string, any>;
constructor(message: string, options?: {
code?: string;
statusCode?: number;
provider?: string;
method?: string;
context?: Record<string, any>;
cause?: Error;
});
}
/**
* Method not implemented - for features that don't exist yet
* Use this when a method is in the interface but not yet built
*/
declare class NotImplementedError extends PayKitError {
constructor(method: string, provider?: string, options?: {
futureSupport?: boolean;
});
}
/**
* Provider limitation - the payment provider doesn't support this feature
* Use this when the provider's API fundamentally doesn't have this capability
*/
declare class ProviderNotSupportedError extends PayKitError {
constructor(method: string, provider: string, options?: {
reason?: string;
alternative?: string;
});
}
/**
* Validation error - input data doesn't match schema
* Use this for Zod validation failures or any input validation
*/
declare class ValidationError extends PayKitError {
constructor(message: string, options?: {
field?: string;
value?: any;
provider?: string;
method?: string;
cause?: Error;
});
/**
* Helper to create ValidationError from Zod error
*/
static fromZodError(zodError: any, provider?: string, method?: string): ValidationError;
}
/**
* Resource not found error
* Use when a requested resource doesn't exist
*/
declare class ResourceNotFoundError extends PayKitError {
constructor(resourceType: string, resourceId: string, provider?: string);
}
/**
* Webhook error - issues with webhook processing
* Use for webhook verification failures or event handling errors
*/
declare class WebhookError extends PayKitError {
constructor(message: string, options?: {
provider?: string;
});
}
/**
* Configuration error - missing or invalid configuration
* Use when required config is missing or invalid
*/
declare class ConfigurationError extends PayKitError {
constructor(message: string, options?: {
provider?: string;
missingKeys?: string[];
});
}
/**
* Operation failed error - generic operation failure
* Use when a provider operation fails unexpectedly
*/
declare class OperationFailedError extends PayKitError {
constructor(operation: string, provider?: string, options?: {
reason?: string;
cause?: Error;
});
}
/**
* Authentication error - API key or auth issues
* Use when provider authentication fails
*/
declare class AuthenticationError extends PayKitError {
constructor(provider: string, message?: string);
}
/**
* Rate limit error - too many requests
* Use when hitting provider rate limits
*/
declare class RateLimitError extends PayKitError {
constructor(provider: string, options?: {
retryAfter?: number;
limit?: number;
});
}
/**
* Invalid type error - wrong data type provided
* Use when type coercion fails or wrong types are passed
*/
declare class InvalidTypeError extends PayKitError {
constructor(field: string, expectedType: string, receivedType: string, options?: {
provider?: string;
method?: string;
});
}
/**
* Constraint violation error - business logic constraint violated
* Use for things like "metadata too long", "amount too small", etc.
*/
declare class ConstraintViolationError extends PayKitError {
constructor(constraint: string, options?: {
value?: any;
limit?: any;
provider?: string;
});
}
declare class UnTraceableError extends Error {
constructor(message: string);
}
export { AuthenticationError, ConfigurationError, ConstraintViolationError, InvalidTypeError, NotImplementedError, OperationFailedError, PayKitError, ProviderNotSupportedError, RateLimitError, ResourceNotFoundError, UnTraceableError, ValidationError, WebhookError };