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

Improve error messages.

This commit is contained in:
Jari Bakken 2014-11-10 14:55:56 +01:00 committed by Ivar Conradi Østhus
parent 71aa307a5f
commit 87c1ee7516

View File

@ -34,7 +34,14 @@ var FeatureTogglesComponent = React.createClass({
}, },
handleError: function (error) { handleError: function (error) {
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))
} else {
this.state.errors.push(error); this.state.errors.push(error);
}
this.forceUpdate(); this.forceUpdate();
}, },
@ -81,6 +88,22 @@ var FeatureTogglesComponent = React.createClass({
this.setState({errors: []}); this.setState({errors: []});
}, },
isClientError: function(error) {
try {
return error.status >= 400 &&
error.status < 500 &&
JSON.parse(error.responseText);
} catch (e) {
if (e instanceof SyntaxError) {
// fall through;
} else {
throw e;
}
}
return false;
},
render: function() { render: function() {
return ( return (
<div> <div>