mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-30 02:56:20 -05:00
Merge pull request #913 from rschamp/bugfix/empty-bodies
Don't set state to undefined API response bodies
This commit is contained in:
commit
60f0ee1ded
1 changed files with 12 additions and 5 deletions
|
@ -4,6 +4,7 @@ var omit = require('lodash.omit');
|
||||||
var React = require('react');
|
var React = require('react');
|
||||||
|
|
||||||
var api = require('../../lib/api');
|
var api = require('../../lib/api');
|
||||||
|
var log = require('../../lib/log');
|
||||||
var render = require('../../lib/render.jsx');
|
var render = require('../../lib/render.jsx');
|
||||||
var sessionActions = require('../../redux/session.js');
|
var sessionActions = require('../../redux/session.js');
|
||||||
var shuffle = require('../../lib/shuffle.js').shuffle;
|
var shuffle = require('../../lib/shuffle.js').shuffle;
|
||||||
|
@ -94,35 +95,40 @@ var Splash = injectIntl(React.createClass({
|
||||||
api({
|
api({
|
||||||
uri: '/proxy/users/' + this.props.session.session.user.username + '/activity?limit=5'
|
uri: '/proxy/users/' + this.props.session.session.user.username + '/activity?limit=5'
|
||||||
}, function (err, body) {
|
}, function (err, body) {
|
||||||
if (!err) this.setState({activity: body});
|
if (!body) return log.error('No response body');
|
||||||
|
if (!err) return this.setState({activity: body});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
getFeaturedGlobal: function () {
|
getFeaturedGlobal: function () {
|
||||||
api({
|
api({
|
||||||
uri: '/proxy/featured'
|
uri: '/proxy/featured'
|
||||||
}, function (err, body) {
|
}, function (err, body) {
|
||||||
if (!err) this.setState({featuredGlobal: body});
|
if (!body) return log.error('No response body');
|
||||||
|
if (!err) return this.setState({featuredGlobal: body});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
getFeaturedCustom: function () {
|
getFeaturedCustom: function () {
|
||||||
api({
|
api({
|
||||||
uri: '/proxy/users/' + this.props.session.session.user.id + '/featured'
|
uri: '/proxy/users/' + this.props.session.session.user.id + '/featured'
|
||||||
}, function (err, body) {
|
}, function (err, body) {
|
||||||
if (!err) this.setState({featuredCustom: body});
|
if (!body) return log.error('No response body');
|
||||||
|
if (!err) return this.setState({featuredCustom: body});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
getNews: function () {
|
getNews: function () {
|
||||||
api({
|
api({
|
||||||
uri: '/news?limit=3'
|
uri: '/news?limit=3'
|
||||||
}, function (err, body) {
|
}, function (err, body) {
|
||||||
if (!err) this.setState({news: body});
|
if (!body) return log.error('No response body');
|
||||||
|
if (!err) return this.setState({news: body});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
getProjectCount: function () {
|
getProjectCount: function () {
|
||||||
api({
|
api({
|
||||||
uri: '/projects/count/all'
|
uri: '/projects/count/all'
|
||||||
}, function (err, body) {
|
}, function (err, body) {
|
||||||
if (!err) this.setState({projectCount: body.count});
|
if (!body) return log.error('No response body');
|
||||||
|
if (!err) return this.setState({projectCount: body.count});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
refreshHomepageCache: function () {
|
refreshHomepageCache: function () {
|
||||||
|
@ -133,6 +139,7 @@ var Splash = injectIntl(React.createClass({
|
||||||
useCsrf: true
|
useCsrf: true
|
||||||
}, function (err, body) {
|
}, function (err, body) {
|
||||||
if (err) return this.setState({refreshCacheStatus: 'fail'});
|
if (err) return this.setState({refreshCacheStatus: 'fail'});
|
||||||
|
if (!body) return log.error('No response body');
|
||||||
if (!body.success) return this.setState({refreshCacheStatus: 'inprogress'});
|
if (!body.success) return this.setState({refreshCacheStatus: 'inprogress'});
|
||||||
return this.setState({refreshCacheStatus: 'pass'});
|
return this.setState({refreshCacheStatus: 'pass'});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
Loading…
Reference in a new issue