properly handle fetch errors
This commit is contained in:
parent
7a5e39f078
commit
07a304cbc1
|
@ -151,13 +151,23 @@ export default class App extends Component {
|
|||
log('loading metrics')
|
||||
|
||||
try {
|
||||
const resp = await fetch(`${DOMAIN}/api/status`)
|
||||
const json = await resp.json()
|
||||
|
||||
this.setState({ metrics: json, loading: false })
|
||||
var resp = await fetch(`${DOMAIN}/api/status`)
|
||||
} catch (err) {
|
||||
this.setState({ error: err.toString() })
|
||||
this.setState({
|
||||
error: `Network error: ${err}`,
|
||||
})
|
||||
}
|
||||
|
||||
if (!resp.ok) {
|
||||
this.setState({
|
||||
error: `Failed to fetch stats (${resp.status} ${resp.statusText})`,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const json = await resp.json()
|
||||
|
||||
this.setState({ metrics: json, loading: false })
|
||||
}
|
||||
|
||||
render () {
|
||||
|
|
Loading…
Reference in New Issue