File tree 3 files changed +52
-8
lines changed
3 files changed +52
-8
lines changed Original file line number Diff line number Diff line change @@ -129,13 +129,6 @@ export class GaxiosError<T = any> extends Error {
129
129
if ( error && 'code' in error && error . code ) {
130
130
this . code = error . code ;
131
131
}
132
-
133
- if ( config . errorRedactor ) {
134
- config . errorRedactor ( {
135
- config : this . config ,
136
- response : this . response ,
137
- } ) ;
138
- }
139
132
}
140
133
}
141
134
@@ -476,7 +469,7 @@ export function defaultErrorRedactor<
476
469
}
477
470
478
471
function redactObject < T extends O [ 'data' ] | R > ( obj : T | null ) {
479
- if ( ! obj ) {
472
+ if ( ! obj || typeof obj !== 'object' ) {
480
473
return ;
481
474
} else if (
482
475
obj instanceof FormData ||
Original file line number Diff line number Diff line change @@ -229,6 +229,10 @@ export class Gaxios implements FetchCompliance {
229
229
return this . _request < T > ( opts ) ;
230
230
}
231
231
232
+ if ( opts . errorRedactor ) {
233
+ opts . errorRedactor ( err ) ;
234
+ }
235
+
232
236
throw err ;
233
237
}
234
238
}
Original file line number Diff line number Diff line change @@ -1128,6 +1128,53 @@ describe('🎏 data handling', () => {
1128
1128
scope . done ( ) ;
1129
1129
}
1130
1130
} ) ;
1131
+
1132
+ it ( 'should redact after final retry' , async ( ) => {
1133
+ const customURL = new URL ( url ) ;
1134
+ customURL . searchParams . append ( 'token' , 'sensitive' ) ;
1135
+ customURL . searchParams . append ( 'client_secret' , 'data' ) ;
1136
+ customURL . searchParams . append ( 'random' , 'non-sensitive' ) ;
1137
+
1138
+ const data = {
1139
+ grant_type : 'urn:ietf:params:oauth:grant-type:jwt-bearer' ,
1140
+ assertion : 'somesensitivedata' ,
1141
+ unrelated : 'data' ,
1142
+ client_secret : 'data' ,
1143
+ } ;
1144
+
1145
+ let retryAttempted = false ;
1146
+ const config : GaxiosOptions = {
1147
+ url : customURL ,
1148
+ method : 'POST' ,
1149
+ data : new URLSearchParams ( data ) ,
1150
+ retry : true ,
1151
+ retryConfig : {
1152
+ httpMethodsToRetry : [ 'POST' ] ,
1153
+ onRetryAttempt : err => {
1154
+ assert . deepStrictEqual ( err . config . data , new URLSearchParams ( data ) ) ;
1155
+ retryAttempted = true ;
1156
+ } ,
1157
+ } ,
1158
+ } ;
1159
+
1160
+ const scope = nock ( url )
1161
+ . post ( '/' , data )
1162
+ . query ( ( ) => true )
1163
+ . reply ( 500 )
1164
+ . post ( '/' , data )
1165
+ . query ( ( ) => true )
1166
+ . reply ( 204 ) ;
1167
+
1168
+ const gaxios = new Gaxios ( ) ;
1169
+
1170
+ try {
1171
+ await gaxios . request ( config ) ;
1172
+
1173
+ assert ( retryAttempted ) ;
1174
+ } finally {
1175
+ scope . done ( ) ;
1176
+ }
1177
+ } ) ;
1131
1178
} ) ;
1132
1179
1133
1180
describe ( '🍂 defaults & instances' , ( ) => {
You can’t perform that action at this time.
0 commit comments