GrafanaUI: Fix error handling from rejected promises in Combobox (#99478)

fix error handling not actually catching rejected promises from options fn
This commit is contained in:
Josh Hunt 2025-01-24 09:55:49 +00:00 committed by GitHub
parent 5da15ccdc4
commit df024793d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,14 +15,16 @@ export function useLatestAsyncCall<T, V>(fn: AsyncFn<T, V>): AsyncFn<T, V> {
const requestCount = latestValueCount.current; const requestCount = latestValueCount.current;
return new Promise<V>((resolve, reject) => { return new Promise<V>((resolve, reject) => {
fn(value).then((result) => { fn(value)
.then((result) => {
// Only resolve if the value is still the latest // Only resolve if the value is still the latest
if (requestCount === latestValueCount.current) { if (requestCount === latestValueCount.current) {
resolve(result); resolve(result);
} else { } else {
reject(new StaleResultError()); reject(new StaleResultError());
} }
}); })
.catch(reject);
}); });
}, },
[fn] [fn]