Skip to content

Commit 4b5475e

Browse files
author
Choe DaeBeom
committed
dnchoe: Wrapping with trycatch for API #158
1 parent 4cb964c commit 4b5475e

File tree

4 files changed

+645
-489
lines changed

4 files changed

+645
-489
lines changed

frontend/src/agent_admin/containers/AgentConfiguration.tsx

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export class AgentConfiguration extends PureComponent<
350350
})
351351
}
352352

353-
public onClickTableRowCall = async (host: string, ip: string) => {
353+
public onClickTableRowCall = (host: string, ip: string) => {
354354
if (this.state.focusedHost === host) return
355355
const {
356356
notify,
@@ -376,59 +376,69 @@ export class AgentConfiguration extends PureComponent<
376376
host
377377
)
378378

379-
getLocalFileReadPromise.then(({data}) => {
380-
const hostData = data.return[0][host]
381-
const hostLocalFileReadData = hostData.substring(
382-
0,
383-
hostData.lastIndexOf('\n')
384-
)
385-
const configObj = TOML.parse(hostLocalFileReadData)
386-
const agent: any = _.get(configObj, 'agent')
379+
getLocalFileReadPromise
380+
.then(({data}) => {
381+
const hostData = data.return[0][host]
382+
const hostLocalFileReadData = hostData.substring(
383+
0,
384+
hostData.lastIndexOf('\n')
385+
)
386+
const configObj = TOML.parse(hostLocalFileReadData)
387+
const agent: any = _.get(configObj, 'agent')
387388

388-
let isChanged = false
389+
let isChanged = false
389390

390-
if (agent.hostname !== host) {
391-
notify(notifyAgentConfigHostNameChanged(agent.hostname, host))
392-
_.set(agent, 'hostname', host)
393-
isChanged = true
394-
}
391+
if (agent.hostname !== host) {
392+
notify(notifyAgentConfigHostNameChanged(agent.hostname, host))
393+
_.set(agent, 'hostname', host)
394+
isChanged = true
395+
}
395396

396-
this.setState({
397-
configScript: TOML.stringify(configObj),
398-
isGetLocalStorage: isChanged,
399-
isApplyBtnDisabled: isChanged ? !isChanged : true,
400-
collectorConfigStatus: RemoteDataState.Done,
401-
configPageStatus: RemoteDataState.Done,
402-
selectedOrg: this.DEFAULT_DROPDOWN_TEXT,
397+
this.setState({
398+
configScript: TOML.stringify(configObj),
399+
isGetLocalStorage: isChanged,
400+
isApplyBtnDisabled: isChanged ? !isChanged : true,
401+
collectorConfigStatus: RemoteDataState.Done,
402+
configPageStatus: RemoteDataState.Done,
403+
selectedOrg: this.DEFAULT_DROPDOWN_TEXT,
404+
})
405+
})
406+
.catch(error => {
407+
console.error(error)
403408
})
404-
})
405409

406410
const getLocalServiceGetRunningPromise = getLocalServiceGetRunning(
407411
saltMasterUrl,
408412
saltMasterToken,
409413
host
410414
)
411415

412-
getLocalServiceGetRunningPromise.then(({data}) => {
413-
const {defaultService} = this.state
414-
const getServiceRunning = defaultService
415-
.filter(m => data.return[0][host].includes(m))
416-
.map(sMeasure => ({
417-
name: sMeasure,
418-
isActivity: false,
419-
}))
420-
421-
const getDefaultMeasure = this.defaultMeasurementsData.map(dMeasure => ({
422-
name: dMeasure,
423-
isActivity: false,
424-
}))
416+
getLocalServiceGetRunningPromise
417+
.then(({data}) => {
418+
const {defaultService} = this.state
419+
const getServiceRunning = defaultService
420+
.filter(m => data.return[0][host].includes(m))
421+
.map(sMeasure => ({
422+
name: sMeasure,
423+
isActivity: false,
424+
}))
425425

426-
this.setState({
427-
serviceMeasurements: getServiceRunning,
428-
defaultMeasurements: getDefaultMeasure,
429-
measurementsStatus: RemoteDataState.Done,
426+
const getDefaultMeasure = this.defaultMeasurementsData.map(
427+
dMeasure => ({
428+
name: dMeasure,
429+
isActivity: false,
430+
})
431+
)
432+
433+
this.setState({
434+
serviceMeasurements: getServiceRunning,
435+
defaultMeasurements: getDefaultMeasure,
436+
measurementsStatus: RemoteDataState.Done,
437+
})
438+
})
439+
.catch(error => {
440+
console.error(error)
430441
})
431-
})
432442
}
433443

434444
public onClickActionCall = async (host: string, isRunning: boolean) => {
@@ -763,7 +773,7 @@ export class AgentConfiguration extends PureComponent<
763773
)
764774
}
765775

766-
private handleFocusedServiceMeasure = ({
776+
private handleFocusedServiceMeasure = async ({
767777
clickPosition,
768778
_thisProps,
769779
}: {
@@ -801,24 +811,25 @@ export class AgentConfiguration extends PureComponent<
801811
? (serviceMeasurements[idx].isActivity = true)
802812
: (serviceMeasurements[idx].isActivity = false)
803813

804-
const getRunnerSaltCmdTelegrafPromise = getRunnerSaltCmdTelegraf(
805-
saltMasterUrl,
806-
saltMasterToken,
807-
measureName
808-
)
809-
810-
getRunnerSaltCmdTelegrafPromise.then(({data}) => {
814+
try {
815+
const {data} = await getRunnerSaltCmdTelegraf(
816+
saltMasterUrl,
817+
saltMasterToken,
818+
measureName
819+
)
811820
this.setState({
812821
serviceMeasurements: [...mapServiceMeasurements],
813822
defaultMeasurements: [...mapDefaultMeasurements],
814823
focusedMeasure: measureName,
815824
focusedMeasurePosition: clickPosition,
816825
description: data.return[0],
817826
})
818-
})
827+
} catch (error) {
828+
console.error(error)
829+
}
819830
}
820831

821-
private handleFocusedDefaultMeasure = ({
832+
private handleFocusedDefaultMeasure = async ({
822833
clickPosition,
823834
_thisProps,
824835
}: {
@@ -856,21 +867,22 @@ export class AgentConfiguration extends PureComponent<
856867
description: globalSetting,
857868
})
858869
} else {
859-
const getRunnerSaltCmdTelegrafPromise = getRunnerSaltCmdTelegraf(
860-
saltMasterUrl,
861-
saltMasterToken,
862-
name
863-
)
864-
865-
getRunnerSaltCmdTelegrafPromise.then(({data}) => {
870+
try {
871+
const {data} = await getRunnerSaltCmdTelegraf(
872+
saltMasterUrl,
873+
saltMasterToken,
874+
name
875+
)
866876
this.setState({
867877
defaultMeasurements: [...mapDefaultMeasurements],
868878
serviceMeasurements: [...mapServiceMeasurements],
869879
focusedMeasure: name,
870880
focusedMeasurePosition: clickPosition,
871881
description: data.return[0],
872882
})
873-
})
883+
} catch (error) {
884+
console.error(error)
885+
}
874886
}
875887
}
876888

0 commit comments

Comments
 (0)