File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
packages/middleware-signing/src Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -89,4 +89,24 @@ describe(awsAuthMiddleware.name, () => {
8989 expect ( getUpdatedSystemClockOffset ) . toHaveBeenCalledWith ( dateHeader , mockSystemClockOffset ) ;
9090 } ) ;
9191 } ) ;
92+
93+ it ( "should update systemClockOffset if error contains ServerTime" , async ( ) => {
94+ const serverTime = new Date ( ) . toString ( ) ;
95+ const options = { ...mockOptions } ;
96+ const signingHandler = awsAuthMiddleware ( options ) ( mockNext , { } ) ;
97+
98+ const mockError = Object . assign ( new Error ( "error" ) , { ServerTime : serverTime } ) ;
99+ mockNext . mockRejectedValue ( mockError ) ;
100+
101+ try {
102+ await signingHandler ( mockSigningHandlerArgs ) ;
103+ fail ( `should throw ${ mockError } ` ) ;
104+ } catch ( error ) {
105+ expect ( error ) . toStrictEqual ( mockError ) ;
106+ }
107+
108+ expect ( options . systemClockOffset ) . toBe ( mockUpdatedSystemClockOffset ) ;
109+ expect ( getUpdatedSystemClockOffset ) . toHaveBeenCalledTimes ( 1 ) ;
110+ expect ( getUpdatedSystemClockOffset ) . toHaveBeenCalledWith ( serverTime , mockSystemClockOffset ) ;
111+ } ) ;
92112} ) ;
Original file line number Diff line number Diff line change @@ -28,6 +28,11 @@ export const awsAuthMiddleware =
2828 signingRegion : context [ "signing_region" ] ,
2929 signingService : context [ "signing_service" ] ,
3030 } ) ,
31+ } ) . catch ( ( error ) => {
32+ if ( error . ServerTime ) {
33+ options . systemClockOffset = getUpdatedSystemClockOffset ( error . ServerTime , options . systemClockOffset ) ;
34+ }
35+ throw error ;
3136 } ) ;
3237
3338 const { headers } = output . response as any ;
You can’t perform that action at this time.
0 commit comments