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

View File

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