@@ -19,26 +19,26 @@ const DecoratorHandler = require('../handler/decorator-handler')
1919class CacheRevalidationHandler extends DecoratorHandler {
2020 #successful = false
2121 /**
22- * @type {(() => void) }
22+ * @type {((boolean ) => void) }
2323 */
24- #successCallback
24+ #callback
2525 /**
2626 * @type {(import('../../types/dispatcher.d.ts').default.DispatchHandlers) }
2727 */
2828 #handler
2929
3030 /**
31- * @param {() => void } successCallback Function to call if the cached value is valid
31+ * @param {(boolean ) => void } callback Function to call if the cached value is valid
3232 * @param {import('../../types/dispatcher.d.ts').default.DispatchHandlers } handler
3333 */
34- constructor ( successCallback , handler ) {
35- if ( typeof successCallback !== 'function' ) {
36- throw new TypeError ( 'successCallback must be a function' )
34+ constructor ( callback , handler ) {
35+ if ( typeof callback !== 'function' ) {
36+ throw new TypeError ( 'callback must be a function' )
3737 }
3838
3939 super ( handler )
4040
41- this . #successCallback = successCallback
41+ this . #callback = callback
4242 this . #handler = handler
4343 }
4444
@@ -107,9 +107,9 @@ class CacheRevalidationHandler extends DecoratorHandler {
107107 * @param {string[] | null } rawTrailers
108108 */
109109 onComplete ( rawTrailers ) {
110- if ( this . #successful) {
111- this . #successCallback ( )
112- } else if ( typeof this . #handler. onComplete === 'function' ) {
110+ this . #callback ( this . #successful)
111+
112+ if ( ! this . #successful && typeof this . #handler. onComplete === 'function' ) {
113113 this . #handler. onComplete ( rawTrailers )
114114 }
115115 }
@@ -120,6 +120,8 @@ class CacheRevalidationHandler extends DecoratorHandler {
120120 * @param {Error } err
121121 */
122122 onError ( err ) {
123+ this . #callback( false )
124+
123125 if ( typeof this . #handler. onError === 'function' ) {
124126 this . #handler. onError ( err )
125127 }
0 commit comments