Handle errors better
This commit is contained in:
parent
34de4d5d2e
commit
89e807b469
|
|
@ -22,5 +22,9 @@ export function serializeQuery(query, extraQuery=[]) {
|
|||
|
||||
export function get(url, query, ...extraQuery) {
|
||||
url = url + serializeQuery(query, extraQuery)
|
||||
return fetch(url).then(res => res.json())
|
||||
return fetch(url)
|
||||
.then( response => {
|
||||
if (!response.ok) { throw response }
|
||||
return response.json()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@ export default class CurrentVisitors extends React.Component {
|
|||
|
||||
updateCount() {
|
||||
return fetch(`/api/stats/${encodeURIComponent(this.props.site.domain)}/current-visitors`)
|
||||
.then(res => res.json())
|
||||
.then( response => {
|
||||
if (!response.ok) { throw response }
|
||||
return response.json()
|
||||
})
|
||||
.then((res) => this.setState({currentVisitors: res}))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue