Skip to content

Commit

Permalink
Handle failed attempts to create a token
Browse files Browse the repository at this point in the history
If the Atmosphere API fails to create a token, the modal would still act as if it was trying to create the token.
Now, it will go back to the initial state of the modal (while still showing the entered name), and will present a notification with an error message.
  • Loading branch information
Calvin Mclean committed Aug 13, 2018
1 parent a0f4060 commit 2983c70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
11 changes: 9 additions & 2 deletions troposphere/static/js/actions/APITokenActions.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import APITokenConstants from "constants/APITokenConstants";
import APIToken from "models/APIToken";
import NotificationController from "controllers/NotificationController";
import Utils from "./Utils";

export default {
create: ({name, atmo_user}, callback) => {
create: ({name, atmo_user}, successCallback, failCallback) => {
if (!name) throw new Error("Missing Token name");
if (!atmo_user) throw new Error("Missing Token author");
let apiToken = new APIToken({
Expand All @@ -18,10 +19,16 @@ export default {
.save()
.done(() => {
Utils.dispatch(APITokenConstants.UPDATE_TOKEN, {apiToken});
callback(apiToken);
successCallback(apiToken);
})
.fail(() => {
Utils.dispatch(APITokenConstants.REMOVE_TOKEN, {apiToken});
NotificationController.error(
"Error creating token.",
"Your login might be expired. If you continue to see this error " +
"after logging in again, contact support."
);
failCallback(apiToken);
});
return apiToken;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,21 @@ export default React.createClass({
this.setState({
isSubmitting: true
});
actions.APITokenActions.create(attributes, (response) => {
this.setState({
isSubmitting: false,
successView: true,
hash: response.changed.token
});
actions.APITokenActions.create(attributes, this.successCallback, this.failCallback);
},

successCallback(response) {
this.setState({
isSubmitting: false,
successView: true,
hash: response.changed.token
});
},

failCallback(response) {
this.setState({
isSubmitting: false,
successView: false
});
},

Expand Down

0 comments on commit 2983c70

Please sign in to comment.