Use async-await syntax to call test-config

pull/10616/head
deniz kusefoglu 2018-01-10 17:46:57 -08:00
parent 39757d86d3
commit 2c32772387
2 changed files with 21 additions and 19 deletions

View File

@ -92,20 +92,19 @@ class AlertTabs extends Component {
}
}
handleTestConfig = section => () => {
testAlertOutput(this.props.kapacitor, section, {})
.then(() => {
this.props.addFlashMessage({
type: 'success',
text: `Successfully relayed an alert to ${section}.`,
})
handleTestConfig = section => async () => {
try {
await testAlertOutput(this.props.kapacitor, section, {})
this.props.addFlashMessage({
type: 'success',
text: `Successfully relayed an alert to ${section}.`,
})
.catch(() => {
this.props.addFlashMessage({
type: 'error',
text: `There was an error relaying an alert to ${section}.`,
})
} catch (error) {
this.props.addFlashMessage({
type: 'error',
text: `There was an error relaying an alert to ${section}.`,
})
}
}
sanitizeProperties = (section, properties) => {

View File

@ -152,15 +152,18 @@ export function updateKapacitorConfigSection(kapacitor, section, properties) {
})
}
export function testAlertOutput(kapacitor, outputName, properties) {
return kapacitorProxy(
kapacitor,
'GET',
'/kapacitor/v1/service-tests'
).then(({data: {services}}) => {
export const testAlertOutput = async (kapacitor, outputName) => {
try {
const {data: {services}} = await kapacitorProxy(
kapacitor,
'GET',
'/kapacitor/v1/service-tests'
)
const service = services.find(s => s.name === outputName)
return kapacitorProxy(kapacitor, 'POST', service.link.href, {})
})
} catch (error) {
// empty
}
}
export function createKapacitorTask(kapacitor, id, type, dbrps, script) {