1- import { CLOCK_SKEW_ERROR_CODES , THROTTLING_ERROR_CODES } from "./constants" ;
2- import { isClockSkewError , isThrottlingError } from "./index" ;
1+ import {
2+ CLOCK_SKEW_ERROR_CODES ,
3+ THROTTLING_ERROR_CODES ,
4+ TRANSIENT_ERROR_CODES ,
5+ TRANSIENT_ERROR_STATUS_CODES
6+ } from "./constants" ;
7+ import { isClockSkewError , isThrottlingError , isTransientError } from "./index" ;
8+ import { SdkError } from "@aws-sdk/types" ;
39
410const checkForErrorType = (
5- isErrorTypeFunc : ( error : Error ) => boolean ,
6- errorName : string ,
11+ isErrorTypeFunc : ( error : SdkError ) => boolean ,
12+ options : { name ?: string ; httpStatusCode ?: number } ,
713 errorTypeResult : boolean
814) => {
9- const error = new Error ( ) ;
10- error . name = errorName ;
15+ const { name, httpStatusCode } = options ;
16+ const error = Object . assign ( new Error ( ) , {
17+ name,
18+ $metadata : { httpStatusCode }
19+ } ) ;
1120 expect ( isErrorTypeFunc ( error ) ) . toBe ( errorTypeResult ) ;
1221} ;
1322
1423describe ( "isClockSkewError" , ( ) => {
1524 CLOCK_SKEW_ERROR_CODES . forEach ( name => {
1625 it ( `should declare error with the name "${ name } " to be a ClockSkew error` , ( ) => {
17- checkForErrorType ( isClockSkewError , name , true ) ;
26+ checkForErrorType ( isClockSkewError , { name } , true ) ;
1827 } ) ;
1928 } ) ;
2029
2130 while ( true ) {
2231 const name = Math . random ( ) . toString ( 36 ) . substring ( 2 ) ;
2332 if ( ! CLOCK_SKEW_ERROR_CODES . includes ( name ) ) {
2433 it ( `should not declare error with the name "${ name } " to be a ClockSkew error` , ( ) => {
25- checkForErrorType ( isClockSkewError , name , false ) ;
34+ checkForErrorType ( isClockSkewError , { name } , false ) ;
2635 } ) ;
2736 break ;
2837 }
@@ -32,15 +41,49 @@ describe("isClockSkewError", () => {
3241describe ( "isThrottlingError" , ( ) => {
3342 THROTTLING_ERROR_CODES . forEach ( name => {
3443 it ( `should declare error with the name "${ name } " to be a Throttling error` , ( ) => {
35- checkForErrorType ( isThrottlingError , name , true ) ;
44+ checkForErrorType ( isThrottlingError , { name } , true ) ;
3645 } ) ;
3746 } ) ;
3847
3948 while ( true ) {
4049 const name = Math . random ( ) . toString ( 36 ) . substring ( 2 ) ;
4150 if ( ! THROTTLING_ERROR_CODES . includes ( name ) ) {
4251 it ( `should not declare error with the name "${ name } " to be a Throttling error` , ( ) => {
43- checkForErrorType ( isThrottlingError , name , false ) ;
52+ checkForErrorType ( isThrottlingError , { name } , false ) ;
53+ } ) ;
54+ break ;
55+ }
56+ }
57+ } ) ;
58+
59+ describe ( "isTransientError" , ( ) => {
60+ TRANSIENT_ERROR_CODES . forEach ( name => {
61+ it ( `should declare error with the name "${ name } " to be a Throttling error` , ( ) => {
62+ checkForErrorType ( isTransientError , { name } , true ) ;
63+ } ) ;
64+ } ) ;
65+
66+ TRANSIENT_ERROR_STATUS_CODES . forEach ( httpStatusCode => {
67+ it ( `should declare error with the HTTP Status Code "${ httpStatusCode } " to be a Throttling error` , ( ) => {
68+ checkForErrorType ( isTransientError , { httpStatusCode } , true ) ;
69+ } ) ;
70+ } ) ;
71+
72+ while ( true ) {
73+ const name = Math . random ( ) . toString ( 36 ) . substring ( 2 ) ;
74+ if ( ! TRANSIENT_ERROR_CODES . includes ( name ) ) {
75+ it ( `should not declare error with the name "${ name } " to be a Throttling error` , ( ) => {
76+ checkForErrorType ( isTransientError , { name } , false ) ;
77+ } ) ;
78+ break ;
79+ }
80+ }
81+
82+ while ( true ) {
83+ const httpStatusCode = Math . ceil ( Math . random ( ) * 10 ** 3 ) ;
84+ if ( ! TRANSIENT_ERROR_STATUS_CODES . includes ( httpStatusCode ) ) {
85+ it ( `should declare error with the HTTP Status Code "${ httpStatusCode } " to be a Throttling error` , ( ) => {
86+ checkForErrorType ( isTransientError , { httpStatusCode } , false ) ;
4487 } ) ;
4588 break ;
4689 }
0 commit comments