Skip to content

Commit ba2ff35

Browse files
authored
Reject with indexeddb errors in RemoteConfig.fetch() (#2381)
* pass the indexeddb errors to the caller. * [AUTOMATED]: Prettier Code Styling
1 parent 638aba6 commit ba2ff35

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

packages/remote-config/src/remote_config.ts

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -129,41 +129,38 @@ export class RemoteConfig implements RemoteConfigType {
129129
* {@link DEFAULT_FETCH_TIMEOUT_SECONDS}.
130130
*/
131131
async fetch(): Promise<void> {
132-
return new Promise(async (resolve, reject) => {
133-
// Aborts the request after the given timeout, causing the fetch call to
134-
// reject with an AbortError.
135-
//
136-
// <p>Aborting after the request completes is a no-op, so we don't need a
137-
// corresponding clearTimeout.
138-
//
139-
// Locating abort logic here because:
140-
// * it uses a developer setting (timeout)
141-
// * it applies to all retries (like curl's max-time arg)
142-
// * it is consistent with the Fetch API's signal input
143-
const abortSignal = new RemoteConfigAbortSignal();
144-
145-
setTimeout(async () => {
146-
// Note a very low delay, eg < 10ms, can elapse before listeners are initialized.
147-
abortSignal.abort();
148-
}, this.settings.fetchTimeoutMillis);
149-
150-
// Catches *all* errors thrown by client so status can be set consistently.
151-
try {
152-
await this._client.fetch({
153-
cacheMaxAgeMillis: this.settings.minimumFetchIntervalMillis,
154-
signal: abortSignal
155-
});
156-
157-
await this._storageCache.setLastFetchStatus('success');
158-
resolve();
159-
} catch (e) {
160-
const lastFetchStatus = hasErrorCode(e, ErrorCode.FETCH_THROTTLE)
161-
? 'throttle'
162-
: 'failure';
163-
await this._storageCache.setLastFetchStatus(lastFetchStatus);
164-
reject(e);
165-
}
166-
});
132+
// Aborts the request after the given timeout, causing the fetch call to
133+
// reject with an AbortError.
134+
//
135+
// <p>Aborting after the request completes is a no-op, so we don't need a
136+
// corresponding clearTimeout.
137+
//
138+
// Locating abort logic here because:
139+
// * it uses a developer setting (timeout)
140+
// * it applies to all retries (like curl's max-time arg)
141+
// * it is consistent with the Fetch API's signal input
142+
const abortSignal = new RemoteConfigAbortSignal();
143+
144+
setTimeout(async () => {
145+
// Note a very low delay, eg < 10ms, can elapse before listeners are initialized.
146+
abortSignal.abort();
147+
}, this.settings.fetchTimeoutMillis);
148+
149+
// Catches *all* errors thrown by client so status can be set consistently.
150+
try {
151+
await this._client.fetch({
152+
cacheMaxAgeMillis: this.settings.minimumFetchIntervalMillis,
153+
signal: abortSignal
154+
});
155+
156+
await this._storageCache.setLastFetchStatus('success');
157+
} catch (e) {
158+
const lastFetchStatus = hasErrorCode(e, ErrorCode.FETCH_THROTTLE)
159+
? 'throttle'
160+
: 'failure';
161+
await this._storageCache.setLastFetchStatus(lastFetchStatus);
162+
throw e;
163+
}
167164
}
168165

169166
async fetchAndActivate(): Promise<boolean> {

0 commit comments

Comments
 (0)