From beb04bd3f6d9caa24665936bac09a374a14441ed Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Wed, 12 Jul 2017 16:14:06 -0700 Subject: [PATCH] Be the async await change --- .../kapacitor/containers/KapacitorRulePage.js | 36 ++++++++++--------- ui/src/shared/apis/index.js | 6 ++-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/ui/src/kapacitor/containers/KapacitorRulePage.js b/ui/src/kapacitor/containers/KapacitorRulePage.js index 7567ff7b3..7bdc4448c 100644 --- a/ui/src/kapacitor/containers/KapacitorRulePage.js +++ b/ui/src/kapacitor/containers/KapacitorRulePage.js @@ -38,25 +38,27 @@ class KapacitorRulePage extends Component { }) } - getKapacitorConfig(kapacitor) - .then(({data: {sections}}) => { - const enabledAlerts = Object.keys(sections).filter(section => { - return ( - _.get( - sections, - [section, 'elements', '0', 'options', 'enabled'], - false - ) && ALERTS.includes(section) - ) - }) - this.setState({kapacitor, enabledAlerts}) + try { + const {data: {sections}} = await getKapacitorConfig(kapacitor) + const enabledAlerts = Object.keys(sections).filter(section => { + return ( + _.get( + sections, + [section, 'elements', '0', 'options', 'enabled'], + false + ) && ALERTS.includes(section) + ) }) - .catch(() => { - addFlashMessage({ - type: 'error', - text: 'There was a problem communicating with Kapacitor', - }) + + this.setState({kapacitor, enabledAlerts}) + } catch (error) { + addFlashMessage({ + type: 'error', + text: 'There was a problem communicating with Kapacitor', }) + console.error(error) + throw error + } } render() { diff --git a/ui/src/shared/apis/index.js b/ui/src/shared/apis/index.js index 5c6e60b1a..6ec40d6e2 100644 --- a/ui/src/shared/apis/index.js +++ b/ui/src/shared/apis/index.js @@ -143,11 +143,11 @@ export function updateKapacitor({ }) } -export function getKapacitorConfig(kapacitor) { - return kapacitorProxy(kapacitor, 'GET', '/kapacitor/v1/config', '') +export const getKapacitorConfig = async kapacitor => { + return await kapacitorProxy(kapacitor, 'GET', '/kapacitor/v1/config', '') } -export function getKapacitorConfigSection(kapacitor, section) { +export const getKapacitorConfigSection = (kapacitor, section) => { return kapacitorProxy(kapacitor, 'GET', `/kapacitor/v1/config/${section}`, '') }