* @param {DispatchFn} dispatch * @param {import('../../types/cache-interceptor.d.ts').default.CacheHandlerOptions} globalOpts * @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} cacheKey * @param {import('../../types/dispatcher.d.ts').default.DispatchHandler} handler * @para
( dispatch, globalOpts, cacheKey, handler, opts, reqCacheControl )
| 115 | * @param {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives | undefined} reqCacheControl |
| 116 | */ |
| 117 | function handleUncachedResponse ( |
| 118 | dispatch, |
| 119 | globalOpts, |
| 120 | cacheKey, |
| 121 | handler, |
| 122 | opts, |
| 123 | reqCacheControl |
| 124 | ) { |
| 125 | if (reqCacheControl?.['only-if-cached']) { |
| 126 | let aborted = false |
| 127 | |
| 128 | const controller = { |
| 129 | paused: false, |
| 130 | rawHeaders: [], |
| 131 | rawTrailers: [], |
| 132 | pause () { |
| 133 | this.paused = true |
| 134 | }, |
| 135 | resume () { |
| 136 | this.paused = false |
| 137 | }, |
| 138 | abort: (reason) => { |
| 139 | aborted = true |
| 140 | handler.onResponseError?.(controller, reason ?? new AbortError()) |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | try { |
| 145 | handler.onRequestStart?.(controller, null) |
| 146 | |
| 147 | if (aborted) { |
| 148 | return |
| 149 | } |
| 150 | |
| 151 | handler.onResponseStart?.(controller, 504, {}, 'Gateway Timeout') |
| 152 | if (aborted) { |
| 153 | return |
| 154 | } |
| 155 | |
| 156 | handler.onResponseEnd?.(controller, {}) |
| 157 | } catch (err) { |
| 158 | if (typeof handler.onResponseError === 'function') { |
| 159 | handler.onResponseError(controller, err) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | return true |
| 164 | } |
| 165 | |
| 166 | return dispatch(opts, new CacheHandler(globalOpts, cacheKey, handler)) |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * @param {import('../../types/dispatcher.d.ts').default.DispatchHandler} handler |
no test coverage detected