From a13265125206af796d647d4023f7faeca9fbb953 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:07:15 +0100 Subject: [PATCH] Refactor async calls to avoid mixing `await` and `then` --- client/src/stores/historyStore.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/client/src/stores/historyStore.ts b/client/src/stores/historyStore.ts index 0ceb16cbb05..4d6dcfd6ef2 100644 --- a/client/src/stores/historyStore.ts +++ b/client/src/stores/historyStore.ts @@ -207,7 +207,7 @@ export const useHistoryStore = defineStore("historyStore", () => { } async function loadTotalHistoryCount() { - await getHistoryCount().then((count) => (totalHistoryCount.value = count)); + totalHistoryCount.value = await getHistoryCount(); } /** TODO: @@ -231,15 +231,17 @@ export const useHistoryStore = defineStore("historyStore", () => { } } const offset = queryString ? 0 : historiesOffset.value; - await getHistoryList(offset, limit, queryString) - .then(async (histories) => { - setHistories(histories); - if (paginate && !queryString && historiesOffset.value == offset) { - await handleTotalCountChange(histories.length); - } - }) - .catch((error) => console.warn(error)) - .finally(() => setHistoriesLoading(false)); + try { + const histories = await getHistoryList(offset, limit, queryString); + setHistories(histories); + if (paginate && !queryString && historiesOffset.value == offset) { + await handleTotalCountChange(histories.length); + } + } catch (error) { + console.warn(error); + } finally { + setHistoriesLoading(false); + } } }