From cd1271fde4aaba7b7abd869ec67113120640ff21 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Wed, 29 Mar 2017 13:38:29 -0700 Subject: [PATCH] Bubble AJAX errors up to fetchTimeSeries --- ui/src/data_explorer/components/Table.js | 20 +++++++++++--------- ui/src/shared/apis/timeSeries.js | 11 +++++++++-- ui/src/utils/queryUrlGenerator.js | 3 ++- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/ui/src/data_explorer/components/Table.js b/ui/src/data_explorer/components/Table.js index 1b515e7007..83f259c42d 100644 --- a/ui/src/data_explorer/components/Table.js +++ b/ui/src/data_explorer/components/Table.js @@ -52,20 +52,22 @@ const ChronoTable = React.createClass({ } }, - fetchCellData(query) { - this.setState({isLoading: true}) + async fetchCellData(query) { + this.setState({isLoading: true}); // second param is db, we want to leave this blank - fetchTimeSeries(query.host, undefined, query.text).then((resp) => { - const cellData = _.get(resp.data, ['results', '0', 'series', '0'], false) + try { + const {data} = await fetchTimeSeries(query.host, undefined, query.text) + const cellData = _.get(data, ['results', '0', 'series', '0'], false); + if (!cellData) { return this.setState({isLoading: false}) } - this.setState({ - cellData, - isLoading: false, - }) - }) + this.setState({cellData, isLoading: false}) + } catch (error) { + console.error(error.message) + this.setState({error: error.message, isLoading: false}) + } }, componentDidMount() { diff --git a/ui/src/shared/apis/timeSeries.js b/ui/src/shared/apis/timeSeries.js index 137e0c6cdf..1b81607a51 100644 --- a/ui/src/shared/apis/timeSeries.js +++ b/ui/src/shared/apis/timeSeries.js @@ -1,5 +1,12 @@ import {proxy} from 'utils/queryUrlGenerator' -export default function fetchTimeSeries(source, database, query) { - return proxy({source, query, database}) +const fetchTimeSeries = async (source, database, query) => { + try { + return await proxy({source, query, database}) + } catch (error) { + console.error('error from proxy: ', error) + throw error + } } + +export default fetchTimeSeries diff --git a/ui/src/utils/queryUrlGenerator.js b/ui/src/utils/queryUrlGenerator.js index a2bdc070d4..fba968da74 100644 --- a/ui/src/utils/queryUrlGenerator.js +++ b/ui/src/utils/queryUrlGenerator.js @@ -12,6 +12,7 @@ export const proxy = async ({source, query, db, rp}) => { }, }) } catch (error) { - console.error(error) // eslint-disable-line no-console + console.error(error) + throw error } }