UNPKG

@mbc-cqrs-serverless/core

Version:
142 lines (141 loc) 5.73 kB
/** * AWS Error Factory * * Provides standardized factory functions for creating AWS SDK errors * used in integration tests. This eliminates code duplication across * test files and ensures consistent error structure. * * Usage: * import { createDynamoDBError, createS3Error } from './utilities/aws-error-factory' * * const error = createDynamoDBError('ProvisionedThroughputExceededException', { * message: 'Rate exceeded', * httpStatusCode: 400, * throttling: true, * }) */ /** * Base AWS error structure used across all AWS SDK errors */ export interface AWSErrorMetadata { httpStatusCode?: number; requestId?: string; extendedRequestId?: string; cfId?: string; attempts?: number; totalRetryDelay?: number; } /** * Extended error type that matches AWS SDK v3 error structure */ export interface AWSError extends Error { name: string; $metadata: AWSErrorMetadata; $fault?: 'client' | 'server'; $retryable?: { throttling?: boolean; }; $service?: string; code?: string; retryAfterSeconds?: number; time?: Date; } /** * Options for creating AWS errors */ export interface CreateAWSErrorOptions { message?: string; httpStatusCode?: number; requestId?: string; throttling?: boolean; fault?: 'client' | 'server'; retryAfterSeconds?: number; code?: string; } /** * Common DynamoDB error names */ export type DynamoDBErrorName = 'ProvisionedThroughputExceededException' | 'ResourceNotFoundException' | 'ConditionalCheckFailedException' | 'ValidationException' | 'TransactionCanceledException' | 'TransactionConflictException' | 'ItemCollectionSizeLimitExceededException' | 'RequestLimitExceeded' | 'InternalServerError' | 'ServiceUnavailable' | 'ThrottlingException' | 'AccessDeniedException'; /** * Creates a DynamoDB-specific error */ export declare function createDynamoDBError(name: DynamoDBErrorName, options?: CreateAWSErrorOptions): AWSError; /** * Common S3 error names */ export type S3ErrorName = 'NoSuchKey' | 'NoSuchBucket' | 'BucketNotEmpty' | 'BucketAlreadyExists' | 'BucketAlreadyOwnedByYou' | 'AccessDenied' | 'InvalidAccessKeyId' | 'SignatureDoesNotMatch' | 'EntityTooLarge' | 'EntityTooSmall' | 'InvalidPart' | 'InvalidPartOrder' | 'NoSuchUpload' | 'SlowDown' | 'InternalError' | 'ServiceUnavailable'; /** * Creates an S3-specific error */ export declare function createS3Error(name: S3ErrorName, options?: CreateAWSErrorOptions): AWSError; /** * Common SQS error names */ export type SQSErrorName = 'QueueDoesNotExist' | 'QueueDeletedRecently' | 'QueueNameExists' | 'InvalidMessageContents' | 'MessageNotInflight' | 'ReceiptHandleIsInvalid' | 'PurgeQueueInProgress' | 'BatchEntryIdsNotDistinct' | 'BatchRequestTooLong' | 'EmptyBatchRequest' | 'InvalidBatchEntryId' | 'TooManyEntriesInBatchRequest' | 'OverLimit' | 'ThrottlingException' | 'AccessDeniedException'; /** * Creates an SQS-specific error */ export declare function createSQSError(name: SQSErrorName, options?: CreateAWSErrorOptions): AWSError; /** * Common SNS error names */ export type SNSErrorName = 'NotFoundException' | 'TopicLimitExceededException' | 'SubscriptionLimitExceededException' | 'InvalidParameterException' | 'InvalidParameterValueException' | 'EndpointDisabledException' | 'PlatformApplicationDisabledException' | 'AuthorizationErrorException' | 'ThrottledException' | 'InternalErrorException'; /** * Creates an SNS-specific error */ export declare function createSNSError(name: SNSErrorName, options?: CreateAWSErrorOptions): AWSError; /** * Common Step Functions error names */ export type SFNErrorName = 'ExecutionDoesNotExist' | 'ExecutionAlreadyExists' | 'ExecutionLimitExceeded' | 'InvalidArn' | 'InvalidDefinition' | 'InvalidExecutionInput' | 'InvalidName' | 'InvalidToken' | 'StateMachineDoesNotExist' | 'StateMachineLimitExceeded' | 'TaskDoesNotExist' | 'TaskTimedOut' | 'ActivityDoesNotExist' | 'ActivityLimitExceeded' | 'ResourceNotFound' | 'ThrottlingException' | 'ServiceQuotaExceededException'; /** * Creates a Step Functions-specific error */ export declare function createSFNError(name: SFNErrorName, options?: CreateAWSErrorOptions): AWSError; /** * Common SES error names */ export type SESErrorName = 'MessageRejected' | 'MailFromDomainNotVerifiedException' | 'ConfigurationSetDoesNotExistException' | 'AccountSendingPausedException' | 'LimitExceededException' | 'NotFoundException' | 'TooManyRequestsException' | 'BadRequestException'; /** * Creates an SES-specific error */ export declare function createSESError(name: SESErrorName, options?: CreateAWSErrorOptions): AWSError; /** * Network error codes */ export type NetworkErrorCode = 'ECONNRESET' | 'ECONNREFUSED' | 'ETIMEDOUT' | 'ENETUNREACH' | 'ENOTFOUND' | 'EPIPE' | 'EAI_AGAIN'; /** * Creates a network-level error */ export declare function createNetworkError(code: NetworkErrorCode, message?: string): Error & { code: string; }; /** * Creates a timeout error */ export declare function createTimeoutError(message?: string): Error & { name: string; code?: string; }; /** * Creates an error for a specific HTTP status code */ export declare function createHttpStatusError(statusCode: number, options?: { name?: string; message?: string; requestId?: string; }): AWSError; /** * Checks if an error is retriable based on AWS SDK v3 patterns */ export declare function isRetriableAWSError(error: AWSError): boolean; /** * Checks if an error is a throttling error */ export declare function isThrottlingError(error: AWSError): boolean; /** * Checks if an error is a network error */ export declare function isNetworkError(error: Error & { code?: string; }): boolean;