Avoid displaying an error when /news returns a 500

This situation probably occurs most frequently when running dev servers while offline, but could also happen if the API is having issues. 500 responses from the API should not take down the homepage so drastically, and are also sometimes unavoidable while working offline.
This commit is contained in:
Ray Schamp 2018-11-05 21:00:12 +00:00
parent 6d8235c7e8
commit 037078d623

View file

@ -71,7 +71,10 @@ class Splash extends React.Component {
getNews () {
api({
uri: '/news?limit=3'
}, (err, body) => {
}, (err, body, resp) => {
if (resp.statusCode !== 200) {
return log.error(`Unexpected status code ${resp.statusCode} received from news request`);
}
if (!body) return log.error('No response body');
if (!err) return this.setState({news: body});
});