import { AWSError } from "aws-sdk" ; import { error } from "../LogUtil" ; const transactionExpiredPattern = RegExp ( "Transaction .* has expired" ) ; export class ClientError extends Error { internal constructor ( message ) { super ( message ) ; Object . setPrototypeOf ( this , ClientError . prototype ) ; this . message = message ; this . name = "ClientError" ; error ( message ) ; } } export class DriverClosedError extends Error { internal constructor ( ) { const message = "Cannot invoke methods on a closed driver. Please create a new driver and retry." ; super ( message ) ; Object . setPrototypeOf ( this , DriverClosedError . prototype ) ; this . message = message ; this . name = "DriverClosedError" ; error ( message ) ; } } export class LambdaAbortedError extends Error { internal constructor ( ) { const message = "Abort called. Halting execution of lambda function." ; super ( message ) ; Object . setPrototypeOf ( this , LambdaAbortedError . prototype ) ; this . message = message ; this . name = "LambdaAbortedError" ; error ( message ) ; } } export class SessionPoolEmptyError extends Error { internal constructor ( ) { const message = "Session pool is empty. Please close existing sessions first before retrying." ; super ( message ) ; Object . setPrototypeOf ( this , SessionPoolEmptyError . prototype ) ; this . message = message ; this . name = "SessionPoolEmptyError" ; error ( message ) ; } } internal export class ExecuteError extends Error { cause : Error ; isRetryable : boolean ; isInvalidSessionException : boolean ; transactionId : string ; constructor ( cause , isRetryable , isInvalidSessionException , transactionId = null ) { const message = "Error containing the context of a failure during Execute." ; super ( message ) ; Object . setPrototypeOf ( this , ExecuteError . prototype ) ; this . cause = cause ; this . isRetryable = isRetryable ; this . isInvalidSessionException = isInvalidSessionException ; this . transactionId = transactionId ; } } param e returns export function isInvalidParameterException ( e ) { return e . code === "InvalidParameterException" ; } param e returns export function isInvalidSessionException ( e ) { return e . code === "InvalidSessionException" ; } param e returns export function isTransactionExpiredException ( e ) { return e . code === "InvalidSessionException" && transactionExpiredPattern . test ( e . message ) ; } param e returns export function isOccConflictException ( e ) { return e . code === "OccConflictException" ; } param e returns export function isResourceNotFoundException ( e ) { return e . code === "ResourceNotFoundException" ; } param e returns export function isResourcePreconditionNotMetException ( e ) { return e . code === "ResourcePreconditionNotMetException" ; } param e returns export function isBadRequestException ( e ) { return e . code === "BadRequestException" ; } param e param onCommit returns internal export function isRetryableException ( e , onCommit ) { const canSdkRetry = onCommit ? false : e . retryable ; return isRetryableStatusCode ( e ) || isOccConflictException ( e ) || canSdkRetry || ( isInvalidSessionException ( e ) && ! isTransactionExpiredException ( e ) ) ; } param e returns function isRetryableStatusCode ( e ) { return ( e . statusCode === 500 ) || ( e . statusCode === 503 ) || ( e . code === "NoHttpResponseException" ) || ( e . code === "SocketTimeoutException" ) ; }