@@ -43,7 +43,7 @@ function Client(options, ctx) {
43
43
this . options = Client . initOptions ( options ) ;
44
44
}
45
45
46
- this . options . cancelFlag = false ; // cancel flag: if true need to be cancelled, default false
46
+ this . options . cancelFlag = false ; // cancel flag: if true need to be cancelled, default false
47
47
48
48
// support custom agent and urllib client
49
49
if ( this . options . urllib ) {
@@ -57,7 +57,7 @@ function Client(options, ctx) {
57
57
this . stsTokenFreshTime = new Date ( ) ;
58
58
59
59
// record the time difference between client and server
60
- this . options . amendTimeSkewed = 0 ;
60
+ this . amendTimeSkewed = 0 ;
61
61
}
62
62
63
63
/**
@@ -68,18 +68,22 @@ module.exports = Client;
68
68
69
69
Client . initOptions = function initOptions ( options ) {
70
70
if ( ! options . stsToken ) {
71
- console . warn ( 'Please use STS Token for safety, see more details at https://help.aliyun.com/document_detail/32077.html' ) ;
71
+ console . warn (
72
+ 'Please use STS Token for safety, see more details at https://help.aliyun.com/document_detail/32077.html'
73
+ ) ;
72
74
}
73
- const opts = Object . assign ( {
74
- secure : isHttpsWebProtocol ( ) ,
75
- // for browser compatibility disable fetch.
76
- useFetch : false ,
77
- } , options ) ;
75
+ const opts = Object . assign (
76
+ {
77
+ secure : isHttpsWebProtocol ( ) ,
78
+ // for browser compatibility disable fetch.
79
+ useFetch : false
80
+ } ,
81
+ options
82
+ ) ;
78
83
79
84
return _initOptions ( opts ) ;
80
85
} ;
81
86
82
-
83
87
/**
84
88
* prototype
85
89
*/
@@ -179,7 +183,12 @@ proto.authorization = function authorization(method, resource, subres, headers)
179
183
parameters : subres
180
184
} ) ;
181
185
182
- return signUtils . authorization ( this . options . accessKeyId , this . options . accessKeySecret , stringToSign , this . options . headerEncoding ) ;
186
+ return signUtils . authorization (
187
+ this . options . accessKeyId ,
188
+ this . options . accessKeySecret ,
189
+ stringToSign ,
190
+ this . options . headerEncoding
191
+ ) ;
183
192
} ;
184
193
185
194
/**
@@ -204,8 +213,8 @@ proto.authorization = function authorization(method, resource, subres, headers)
204
213
proto . request = async function ( params ) {
205
214
if ( this . options . retryMax ) {
206
215
return await retry ( request . bind ( this ) , this . options . retryMax , {
207
- errorHandler : ( err ) => {
208
- const _errHandle = ( _err ) => {
216
+ errorHandler : err => {
217
+ const _errHandle = _err => {
209
218
if ( params . stream ) return false ;
210
219
const statusErr = [ - 1 , - 2 ] . includes ( _err . status ) ;
211
220
const requestErrorRetryHandle = this . options . requestErrorRetryHandle || ( ( ) => true ) ;
@@ -233,7 +242,14 @@ async function request(params) {
233
242
const useStream = ! ! params . stream ;
234
243
try {
235
244
result = await this . urllib . request ( reqParams . url , reqParams . params ) ;
236
- this . debug ( 'response %s %s, got %s, headers: %j' , params . method , reqParams . url , result . status , result . headers , 'info' ) ;
245
+ this . debug (
246
+ 'response %s %s, got %s, headers: %j' ,
247
+ params . method ,
248
+ reqParams . url ,
249
+ result . status ,
250
+ result . headers ,
251
+ 'info'
252
+ ) ;
237
253
} catch ( err ) {
238
254
reqErr = err ;
239
255
}
@@ -242,7 +258,7 @@ async function request(params) {
242
258
err = await this . requestError ( result ) ;
243
259
// not use stream
244
260
if ( err . code === 'RequestTimeTooSkewed' && ! useStream ) {
245
- this . options . amendTimeSkewed = + new Date ( err . serverTime ) - new Date ( ) ;
261
+ this . amendTimeSkewed = + new Date ( err . serverTime ) - new Date ( ) ;
246
262
return await this . request ( params ) ;
247
263
}
248
264
err . params = params ;
@@ -282,7 +298,7 @@ proto._escape = function _escape(name) {
282
298
*/
283
299
284
300
proto . _getUserAgent = function _getUserAgent ( ) {
285
- const agent = ( process && process . browser ) ? 'js' : 'nodejs' ;
301
+ const agent = process && process . browser ? 'js' : 'nodejs' ;
286
302
const sdk = `aliyun-sdk-${ agent } /${ pkg . version } ` ;
287
303
let plat = platform . description ;
288
304
if ( ! plat && process ) {
@@ -306,7 +322,7 @@ proto._checkUserAgent = function _checkUserAgent(ua) {
306
322
*/
307
323
308
324
proto . checkBrowserAndVersion = function checkBrowserAndVersion ( name , version ) {
309
- return ( ( bowser . name === name ) && ( bowser . version . split ( '.' ) [ 0 ] === version ) ) ;
325
+ return bowser . name === name && bowser . version . split ( '.' ) [ 0 ] === version ;
310
326
} ;
311
327
312
328
/**
@@ -321,16 +337,20 @@ proto.parseXML = function parseXMLThunk(str) {
321
337
if ( Buffer . isBuffer ( str ) ) {
322
338
str = str . toString ( ) ;
323
339
}
324
- xml . parseString ( str , {
325
- explicitRoot : false ,
326
- explicitArray : false
327
- } , ( err , result ) => {
328
- if ( err ) {
329
- reject ( err ) ;
330
- } else {
331
- resolve ( result ) ;
340
+ xml . parseString (
341
+ str ,
342
+ {
343
+ explicitRoot : false ,
344
+ explicitArray : false
345
+ } ,
346
+ ( err , result ) => {
347
+ if ( err ) {
348
+ reject ( err ) ;
349
+ } else {
350
+ resolve ( result ) ;
351
+ }
332
352
}
333
- } ) ;
353
+ ) ;
334
354
} ) ;
335
355
} ;
336
356
@@ -344,7 +364,8 @@ proto.parseXML = function parseXMLThunk(str) {
344
364
proto . requestError = async function requestError ( result ) {
345
365
let err = null ;
346
366
if ( ! result . data || ! result . data . length ) {
347
- if ( result . status === - 1 || result . status === - 2 ) { // -1 is net error , -2 is timeout
367
+ if ( result . status === - 1 || result . status === - 2 ) {
368
+ // -1 is net error , -2 is timeout
348
369
err = new Error ( result . message ) ;
349
370
err . name = result . name ;
350
371
err . status = result . status ;
@@ -375,7 +396,7 @@ proto.requestError = async function requestError(result) {
375
396
376
397
let info ;
377
398
try {
378
- info = await this . parseXML ( message ) || { } ;
399
+ info = ( await this . parseXML ( message ) ) || { } ;
379
400
} catch ( error ) {
380
401
this . debug ( message , 'error' ) ;
381
402
error . message += `\nraw xml: ${ message } ` ;
@@ -384,7 +405,7 @@ proto.requestError = async function requestError(result) {
384
405
return error ;
385
406
}
386
407
387
- let msg = info . Message || ( `unknow request error, status: ${ result . status } ` ) ;
408
+ let msg = info . Message || `unknow request error, status: ${ result . status } ` ;
388
409
if ( info . Condition ) {
389
410
msg += ` (condition: ${ info . Condition } )` ;
390
411
}
@@ -400,4 +421,3 @@ proto.requestError = async function requestError(result) {
400
421
this . debug ( 'generate error %j' , err , 'error' ) ;
401
422
return err ;
402
423
} ;
403
-
0 commit comments