From df024793d83047c736a78aebcec4b269da35d470 Mon Sep 17 00:00:00 2001 From: Josh Hunt Date: Fri, 24 Jan 2025 09:55:49 +0000 Subject: [PATCH] GrafanaUI: Fix error handling from rejected promises in Combobox (#99478) fix error handling not actually catching rejected promises from options fn --- .../components/Combobox/useLatestAsyncCall.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/grafana-ui/src/components/Combobox/useLatestAsyncCall.ts b/packages/grafana-ui/src/components/Combobox/useLatestAsyncCall.ts index df6747ebab9..0b1a4916a24 100644 --- a/packages/grafana-ui/src/components/Combobox/useLatestAsyncCall.ts +++ b/packages/grafana-ui/src/components/Combobox/useLatestAsyncCall.ts @@ -15,14 +15,16 @@ export function useLatestAsyncCall(fn: AsyncFn): AsyncFn { const requestCount = latestValueCount.current; return new Promise((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]