@@ -149,6 +149,7 @@ class Auth {
149
149
* @param {String } opts.cache.key
150
150
* @param {String } opts.cache.action
151
151
* @param {Boolean } opts.cache.onNotFound
152
+ * @param {Object } [opts.error = {}] Error options
152
153
* @param {Number } retry Allow retries in case of expired token
153
154
*
154
155
* @returns {Promise<{} | Array<{}>> }
@@ -166,7 +167,8 @@ class Auth {
166
167
isPublic : false ,
167
168
cache : false ,
168
169
timeout : 60000 ,
169
- deadline : 90000
170
+ deadline : 90000 ,
171
+ error : { }
170
172
} ,
171
173
opts
172
174
) ;
@@ -243,7 +245,10 @@ class Auth {
243
245
opts . cache . action === this . cache . actions . get &&
244
246
opts . cache . onNotFound &&
245
247
error . status === 404 &&
246
- error . typeof !== CoreError . CachedNotFound
248
+ ! (
249
+ error instanceof CoreError &&
250
+ error . typeof . name === CoreError . CachedNotFound . name
251
+ )
247
252
) {
248
253
await this . executeCacheOp ( {
249
254
value : false ,
@@ -255,7 +260,10 @@ class Auth {
255
260
if (
256
261
! opts . isPublic &&
257
262
error . status === 401 &&
258
- error . typeof !== CoreError . MaxAuthenticatedRequestsReached
263
+ ! (
264
+ error instanceof CoreError &&
265
+ error . typeof . name === CoreError . MaxAuthenticatedRequestsReached . name
266
+ )
259
267
) {
260
268
this . access . failed = true ;
261
269
return this . send ( service , method , url , opts , ++ retry ) ;
@@ -267,7 +275,8 @@ class Auth {
267
275
service ,
268
276
method ,
269
277
this . timeDelta ( begin ) ,
270
- opts . query
278
+ opts . query ,
279
+ opts . error
271
280
) ;
272
281
}
273
282
}
@@ -277,28 +286,37 @@ class Auth {
277
286
*
278
287
* @private
279
288
*
280
- * @param {typeof Error } error Error returned
281
- * @param {String } url Endpoint
282
- * @param {String } service Core service requested
283
- * @param {String } method REST method used
284
- * @param {Number } tDelta Request time in ms
285
- * @param {Object } query The query sent
289
+ * @param {typeof Error } error Error returned
290
+ * @param {String } url Endpoint
291
+ * @param {String } service Core service requested
292
+ * @param {String } method REST method used
293
+ * @param {Number } tDelta Request time in ms
294
+ * @param {Object } query The query sent
295
+ * @param {Object } opts Additional options
296
+ * @param {Boolean } [opts.mute=false] Whether to mute the error log
286
297
*
287
298
* @returns {CoreError }
288
299
*/
289
- getError ( error , url , service , method , tDelta , query ) {
300
+ getError ( error , url , service , method , tDelta , query , opts = { } ) {
301
+ opts = { mute : false , ...opts } ;
302
+
290
303
const errorText =
291
304
! ! error . response && ! ! error . response . text
292
305
? error . response . text
306
+ : error instanceof CoreError && ( error . isInternal || error . isCache )
307
+ ? error . typeof . name
293
308
: error . stack ;
294
- this . log (
295
- `${ service } ${ method } , code: ${
296
- error . status
297
- } , t: ${ tDelta } ms -> url: ${ url } , query: ${ JSON . stringify (
298
- query || { }
299
- ) } -> error response ${ errorText } `,
300
- 'error'
301
- ) ;
309
+
310
+ if ( ! opts . mute ) {
311
+ this . log (
312
+ `${ service } ${ method } , code: ${
313
+ error . isCache ? 'CACHED' : error . status
314
+ } , t: ${ tDelta } ms -> url: ${ url } , query: ${ JSON . stringify (
315
+ query || { }
316
+ ) } -> error response ${ errorText } `,
317
+ 'error'
318
+ ) ;
319
+ }
302
320
303
321
if ( error instanceof CoreError ) {
304
322
return error ;
0 commit comments