Handle errors with scalar-oauthing

Handle error getting the scalar token and check for non-success status codes in the response handler (because apparently browser-request doesn't consider that an error).
This commit is contained in:
David Baker 2016-06-06 17:55:45 +01:00
parent fdcebe1e56
commit 15dccd9871
2 changed files with 10 additions and 0 deletions

View file

@ -32,6 +32,8 @@ class ScalarAuthClient {
}, (err, response, body) => {
if (err) {
defer.reject(err);
} else if (response.statusCode / 100 !== 2) {
defer.reject({statusCode: response.statusCode});
} else {
defer.resolve(body.access_token);
}

View file

@ -60,6 +60,8 @@ module.exports = React.createClass({
tags: tags,
areNotifsMuted: areNotifsMuted,
isRoomPublished: this._originalIsRoomPublished, // loaded async in componentWillMount
scalar_token: null,
scalar_error: null,
};
},
@ -75,6 +77,8 @@ module.exports = React.createClass({
this.getScalarToken().done((token) => {
this.setState({scalar_token: token});
}, (err) => {
this.setState({scalar_error: err});
});
dis.dispatch({
@ -578,6 +582,10 @@ module.exports = React.createClass({
<a href="#" onClick={ this.onManageIntegrations }>Manage integrations</a>
</div>
);
} else if (this.state.scalar_error) {
integrations_section = <div className="error">
Unable to contact integrations server
</div>;
} else {
integrations_section = <Loader />;
}