1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Don't repeat error messages infinitely

This commit is contained in:
Jari Bakken 2014-11-10 15:25:27 +01:00
parent 20d1c67f01
commit 55a4f476c9

View File

@ -37,9 +37,11 @@ var FeatureTogglesComponent = React.createClass({
if (this.isClientError(error)) {
// TODO: catch SyntaxError
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 {
this.state.errors.push(error);
this.addError(error);
}
this.forceUpdate();
@ -88,6 +90,12 @@ var FeatureTogglesComponent = React.createClass({
this.setState({errors: []});
},
addError: function(msg) {
if (this.state.errors[this.state.errors.length - 1] !== msg) {
this.state.errors.push(msg);
}
},
isClientError: function(error) {
try {
return error.status >= 400 &&