| 350 | }; |
| 351 | |
| 352 | const handleFailure = (error: unknown) => { |
| 353 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 354 | this.debug(`onRefresh failed: ${errorMessage}`); |
| 355 | // Do NOT mutate _lastRefreshInfo — failure must not look like success. |
| 356 | const failureInfo: RefreshFailureInfo = { timestamp: Date.now(), trigger, errorMessage }; |
| 357 | |
| 358 | finalizeInFlight(); |
| 359 | |
| 360 | try { |
| 361 | this.onRefreshError?.(failureInfo); |
| 362 | } catch (callbackError) { |
| 363 | console.error("[RefreshController] onRefreshError callback threw", callbackError); |
| 364 | } |
| 365 | }; |
| 366 | |
| 367 | // Unified promise pipeline: normalizes sync throws and async rejections |
| 368 | // into a single failure path so all errors are handled identically. |