lift error handling to componentDidMount
This commit is contained in:
parent
257febd9cc
commit
243c23ec2b
1 changed files with 9 additions and 15 deletions
|
@ -20,8 +20,12 @@ export default class Dashboard extends Component {
|
|||
}
|
||||
|
||||
async componentDidMount () {
|
||||
await this.loadMetrics()
|
||||
await this.loadIncident()
|
||||
try {
|
||||
await this.loadMetrics()
|
||||
await this.loadIncident()
|
||||
} catch (error) {
|
||||
this.setState({ error: error.toString() })
|
||||
}
|
||||
|
||||
this.setState({ loading: false })
|
||||
if (this.state.error) {
|
||||
|
@ -95,24 +99,14 @@ export default class Dashboard extends Component {
|
|||
async loadMetrics () {
|
||||
log('loading metrics')
|
||||
|
||||
try {
|
||||
var resp = await strictFetch(`${DOMAIN}/api/status`)
|
||||
} catch (error) {
|
||||
this.setState({ error })
|
||||
}
|
||||
|
||||
const resp = await strictFetch(`${DOMAIN}/api/status`)
|
||||
this.setState({ metrics: await resp.json() })
|
||||
}
|
||||
|
||||
async loadIncident () {
|
||||
log('loading current incident')
|
||||
|
||||
try {
|
||||
var resp = await strictFetch(`${DOMAIN}/api/incidents/current`)
|
||||
} catch (error) {
|
||||
this.setState({ error })
|
||||
}
|
||||
|
||||
const resp = await strictFetch(`${DOMAIN}/api/incidents/current`)
|
||||
this.setState({ incident: await resp.json() })
|
||||
}
|
||||
|
||||
|
@ -149,7 +143,7 @@ export default class Dashboard extends Component {
|
|||
|
||||
{this.state.error ? (
|
||||
<div className="error">
|
||||
Error: {this.state.error}
|
||||
{this.state.error}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
|
|
Loading…
Reference in a new issue