@@ -15,6 +15,54 @@ describe("throw200ExceptionsMiddlewareOptions", () => {
15
15
jest . clearAllMocks ( ) ;
16
16
} ) ;
17
17
18
+ describe ( "exceptions for code < 200 and >= 300" , ( ) => {
19
+ mockStreamCollector . mockResolvedValue ( Buffer . from ( "" ) ) ;
20
+ mockUtf8Encoder . mockReturnValue ( "" ) ;
21
+ it ( "throws an exception if code is less than 200" , async ( ) => {
22
+ mockNextHandler . mockReturnValue ( {
23
+ response : new HttpResponse ( {
24
+ statusCode : 199 ,
25
+ headers : { } ,
26
+ body : "" ,
27
+ } ) ,
28
+ } ) ;
29
+ const handler = throw200ExceptionsMiddleware ( mockConfig ) ( mockNextHandler , { } as any ) ;
30
+ try {
31
+ await handler ( {
32
+ input : { } ,
33
+ request : new HttpRequest ( {
34
+ hostname : "s3.us-east-1.amazonaws.com" ,
35
+ } ) ,
36
+ } ) ;
37
+ } catch ( e ) {
38
+ expect ( e ) . toBeDefined ( ) ;
39
+ expect ( e . name ) . toEqual ( "InternalError" ) ;
40
+ expect ( e . message ) . toEqual ( "S3 aborted request" ) ;
41
+ }
42
+ } ) ;
43
+ it ( "throws an exception if code is greater than or equal to 300" , async ( ) => {
44
+ mockNextHandler . mockReturnValue ( {
45
+ response : new HttpResponse ( {
46
+ statusCode : 300 ,
47
+ headers : { } ,
48
+ body : "" ,
49
+ } ) ,
50
+ } ) ;
51
+ const handler = throw200ExceptionsMiddleware ( mockConfig ) ( mockNextHandler , { } as any ) ;
52
+ try {
53
+ await handler ( {
54
+ input : { } ,
55
+ request : new HttpRequest ( {
56
+ hostname : "s3.us-east-1.amazonaws.com" ,
57
+ } ) ,
58
+ } ) ;
59
+ } catch ( e ) {
60
+ expect ( e ) . toBeDefined ( ) ;
61
+ expect ( e . name ) . toEqual ( "InternalError" ) ;
62
+ expect ( e . message ) . toEqual ( "S3 aborted request" ) ;
63
+ }
64
+ } ) ;
65
+ } ) ;
18
66
it ( "should throw if response body is empty" , async ( ) => {
19
67
expect . assertions ( 3 ) ;
20
68
mockStreamCollector . mockResolvedValue ( Buffer . from ( "" ) ) ;
0 commit comments