From b4428473ec3162803f17623ab205e00957fc3797 Mon Sep 17 00:00:00 2001 From: Ewout Stortenbeker Date: Wed, 1 Apr 2026 13:14:52 +0000 Subject: [PATCH] This fixes a situation where `get` never yields an error (or result): * A value does not exist in cache, and the (resolved) cache promise is handled first * The server value can't be loaded because of an error (unauthorized or server error) and the (rejected) server promise is handled second. --- src/api-web.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api-web.ts b/src/api-web.ts index f2591e8..dd5dd30 100644 --- a/src/api-web.ts +++ b/src/api-web.ts @@ -2018,8 +2018,10 @@ export class WebApi extends Api { // Get both, use cached value if available and server version takes too long return new Promise((resolve, reject) => { let wait = true, done = false; + const handledSources = []; const gotValue = (source: 'cache' | 'server', val: { value: any; context: any; cursor?: string }) => { this.debug.verbose(`Got ${source} value of "${path}":`, val); + handledSources.push(source); if (done) { return; } const { value, context, cursor } = val; if (source === 'server') { @@ -2064,9 +2066,9 @@ export class WebApi extends Api { }; const errors = [] as Array<{ source: 'cache' | 'server', error: any }>; const gotError = (source: 'cache' | 'server', error: any) => { - errors.push({ source, error }); - if (errors.length === 2) { - // Both failed, reject with server error + handledSources.push(source); + if (handledSources.length === 2) { + // Both failed, or server failed and cache had no value, reject with server error reject(errors.find(e => e.source === 'server')?.error); } };