This is an automated email from the ASF dual-hosted git repository. bbovenzi pushed a commit to branch handle-grid-autorefresh-errors in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 9c8f84b794673f06b808f8c35be652d416671e97 Author: Brent Bovenzi <[email protected]> AuthorDate: Thu Apr 7 14:29:16 2022 -0400 Better handle auto-refresh errors --- airflow/www/static/js/tree/api/useTreeData.js | 30 ++++++++++++---------- .../www/static/js/tree/api/useTreeData.test.jsx | 3 +-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/airflow/www/static/js/tree/api/useTreeData.js b/airflow/www/static/js/tree/api/useTreeData.js index 83d638f0e0..ddb0a9dfed 100644 --- a/airflow/www/static/js/tree/api/useTreeData.js +++ b/airflow/www/static/js/tree/api/useTreeData.js @@ -17,9 +17,11 @@ * under the License. */ -/* global treeData, autoRefreshInterval, fetch */ +/* global treeData, autoRefreshInterval */ import { useQuery } from 'react-query'; +import axios from 'axios'; +import { useToast } from '@chakra-ui/react'; import { getMetaValue } from '../../utils'; import { useAutoRefresh } from '../context/autorefresh'; @@ -39,26 +41,26 @@ const useTreeData = () => { }; const initialData = formatData(treeData, emptyData); const { isRefreshOn, stopRefresh } = useAutoRefresh(); + const toast = useToast(); return useQuery('treeData', async () => { try { const root = urlRoot ? `&root=${urlRoot}` : ''; const base = baseDate ? `&base_date=${baseDate}` : ''; - const resp = await fetch(`${treeDataUrl}?dag_id=${dagId}&num_runs=${numRuns}${root}${base}`); - if (resp) { - let newData = await resp.json(); - newData = formatData(newData); - // turn off auto refresh if there are no active runs - if (!areActiveRuns(newData.dagRuns)) stopRefresh(); - return newData; - } + const newData = await axios.get(`${treeDataUrl}?dag_id=${dagId}&num_runs=${numRuns}${root}${base}`); + // turn off auto refresh if there are no active runs + if (!areActiveRuns(newData.dagRuns)) stopRefresh(); + return newData; } catch (e) { stopRefresh(); - console.error(e); + // Display error in a toast message + toast({ + title: 'Auto-refresh Error', + description: e.message, + isClosable: true, + status: 'error', + }); + throw (e); } - return { - groups: {}, - dagRuns: [], - }; }, { // only enabled and refetch if the refresh switch is on enabled: isRefreshOn, diff --git a/airflow/www/static/js/tree/api/useTreeData.test.jsx b/airflow/www/static/js/tree/api/useTreeData.test.jsx index ab6b73a97b..03d99ea7e0 100644 --- a/airflow/www/static/js/tree/api/useTreeData.test.jsx +++ b/airflow/www/static/js/tree/api/useTreeData.test.jsx @@ -22,7 +22,7 @@ import { QueryClient, QueryClientProvider } from 'react-query'; import useTreeData from './useTreeData'; import { AutoRefreshProvider } from '../context/autorefresh'; -/* global describe, test, expect, jest, beforeAll */ +/* global describe, test, expect, beforeAll */ const pendingTreeData = { groups: {}, @@ -55,7 +55,6 @@ const Wrapper = ({ children }) => { describe('Test useTreeData hook', () => { beforeAll(() => { global.autoRefreshInterval = 5; - global.fetch = jest.fn(); }); test('data is valid camelcase json', () => {
