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 () {
|
async componentDidMount () {
|
||||||
await this.loadMetrics()
|
try {
|
||||||
await this.loadIncident()
|
await this.loadMetrics()
|
||||||
|
await this.loadIncident()
|
||||||
|
} catch (error) {
|
||||||
|
this.setState({ error: error.toString() })
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({ loading: false })
|
this.setState({ loading: false })
|
||||||
if (this.state.error) {
|
if (this.state.error) {
|
||||||
|
@ -95,24 +99,14 @@ export default class Dashboard extends Component {
|
||||||
async loadMetrics () {
|
async loadMetrics () {
|
||||||
log('loading metrics')
|
log('loading metrics')
|
||||||
|
|
||||||
try {
|
const resp = await strictFetch(`${DOMAIN}/api/status`)
|
||||||
var resp = await strictFetch(`${DOMAIN}/api/status`)
|
|
||||||
} catch (error) {
|
|
||||||
this.setState({ error })
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({ metrics: await resp.json() })
|
this.setState({ metrics: await resp.json() })
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadIncident () {
|
async loadIncident () {
|
||||||
log('loading current incident')
|
log('loading current incident')
|
||||||
|
|
||||||
try {
|
const resp = await strictFetch(`${DOMAIN}/api/incidents/current`)
|
||||||
var resp = await strictFetch(`${DOMAIN}/api/incidents/current`)
|
|
||||||
} catch (error) {
|
|
||||||
this.setState({ error })
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({ incident: await resp.json() })
|
this.setState({ incident: await resp.json() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +143,7 @@ export default class Dashboard extends Component {
|
||||||
|
|
||||||
{this.state.error ? (
|
{this.state.error ? (
|
||||||
<div className="error">
|
<div className="error">
|
||||||
Error: {this.state.error}
|
{this.state.error}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue