lift error handling to componentDidMount

This commit is contained in:
slice 2018-07-18 15:19:53 -07:00
parent 257febd9cc
commit 243c23ec2b
No known key found for this signature in database
GPG Key ID: 1508C19D7436A26D
1 changed files with 9 additions and 15 deletions

View File

@ -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}