@@ -9,6 +9,8 @@ const CacheRevalidationHandler = require('../handler/cache-revalidation-handler'
99const { assertCacheStore, assertCacheMethods, makeCacheKey, normalizeHeaders, parseCacheControlHeader } = require ( '../util/cache.js' )
1010const { AbortError } = require ( '../core/errors.js' )
1111
12+ const nop = ( ) => { }
13+
1214/**
1315 * @typedef {(options: import('../../types/dispatcher.d.ts').default.DispatchOptions, handler: import('../../types/dispatcher.d.ts').default.DispatchHandler) => void } DispatchFn
1416 */
@@ -102,7 +104,7 @@ function handleUncachedResponse (
102104 }
103105
104106 if ( typeof handler . onHeaders === 'function' ) {
105- handler . onHeaders ( 504 , [ ] , ( ) => { } , 'Gateway Timeout' )
107+ handler . onHeaders ( 504 , [ ] , nop , 'Gateway Timeout' )
106108 if ( aborted ) {
107109 return
108110 }
@@ -325,7 +327,7 @@ function handleResult (
325327 if ( success ) {
326328 sendCachedValue ( handler , opts , result , age , context , true )
327329 } else if ( util . isStream ( result . body ) ) {
328- result . body . on ( 'error' , ( ) => { } ) . destroy ( )
330+ result . body . on ( 'error' , nop ) . destroy ( )
329331 }
330332 } ,
331333 new CacheHandler ( globalOpts , cacheKey , handler ) ,
@@ -336,7 +338,7 @@ function handleResult (
336338
337339 // Dump request body.
338340 if ( util . isStream ( opts . body ) ) {
339- opts . body . on ( 'error' , ( ) => { } ) . destroy ( )
341+ opts . body . on ( 'error' , nop ) . destroy ( )
340342 }
341343
342344 sendCachedValue ( handler , opts , result , age , null , false )
@@ -405,18 +407,17 @@ module.exports = (opts = {}) => {
405407 const result = store . get ( cacheKey )
406408
407409 if ( result && typeof result . then === 'function' ) {
408- result . then ( result => {
409- handleResult ( dispatch ,
410+ return result
411+ . then ( result => handleResult ( dispatch ,
410412 globalOpts ,
411413 cacheKey ,
412414 handler ,
413415 opts ,
414416 reqCacheControl ,
415417 result
416- )
417- } )
418+ ) )
418419 } else {
419- handleResult (
420+ return handleResult (
420421 dispatch ,
421422 globalOpts ,
422423 cacheKey ,
@@ -426,8 +427,6 @@ module.exports = (opts = {}) => {
426427 result
427428 )
428429 }
429-
430- return true
431430 }
432431 }
433432}
0 commit comments