1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

Don't repeat error messages infinitely

This commit is contained in:
Jari Bakken 2014-11-10 15:25:27 +01:00 committed by Ivar Conradi Østhus
parent a031900b3e
commit 12b87c69c8

View File

@ -37,9 +37,11 @@ var FeatureTogglesComponent = React.createClass({
if (this.isClientError(error)) { if (this.isClientError(error)) {
// TODO: catch SyntaxError // TODO: catch SyntaxError
var errors = JSON.parse(error.responseText) var errors = JSON.parse(error.responseText)
errors.forEach(function(e) { this.state.errors.push(e.msg); }.bind(this)) errors.forEach(function(e) { this.addError(e.msg); }.bind(this))
} else if (error.status === 0) {
this.addError("server unreachable");
} else { } else {
this.state.errors.push(error); this.addError(error);
} }
this.forceUpdate(); this.forceUpdate();
@ -88,6 +90,12 @@ var FeatureTogglesComponent = React.createClass({
this.setState({errors: []}); this.setState({errors: []});
}, },
addError: function(msg) {
if (this.state.errors[this.state.errors.length - 1] !== msg) {
this.state.errors.push(msg);
}
},
isClientError: function(error) { isClientError: function(error) {
try { try {
return error.status >= 400 && return error.status >= 400 &&