diff options
author | Robert Kowalski <rok@kowalski.gd> | 2014-03-06 11:37:17 -0500 |
---|---|---|
committer | suelockwood <deathbear@apache.org> | 2014-03-06 11:40:30 -0500 |
commit | b63ff1b50b7bde0c8f1f95988d076dda63f41fed (patch) | |
tree | 24fb62d253cf341df384c74c2be07577516ee8c7 | |
parent | fb4e845229bf192439eb88a875d9e879784e5711 (diff) | |
download | couchdb-b63ff1b50b7bde0c8f1f95988d076dda63f41fed.tar.gz |
Fauxton: dry up promise error callbacks
Fauxton: Fix error if anon. user tries to create Admins
Fixes #COUCHDB-2170
-rw-r--r-- | src/fauxton/app/addons/auth/resources.js | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/src/fauxton/app/addons/auth/resources.js b/src/fauxton/app/addons/auth/resources.js index 2e359c95b..71744e37c 100644 --- a/src/fauxton/app/addons/auth/resources.js +++ b/src/fauxton/app/addons/auth/resources.js @@ -20,6 +20,18 @@ function (app, FauxtonAPI, CouchdbSession) { var Auth = new FauxtonAPI.addon(); + var promiseErrorHandler = function (xhr, type, msg) { + msg = xhr; + if (arguments.length === 3) { + msg = xhr.responseJSON.reason; + } + + FauxtonAPI.addNotification({ + msg: msg, + type: 'error' + }); + }; + var Admin = Backbone.Model.extend({ url: function () { @@ -58,7 +70,6 @@ function (app, FauxtonAPI, CouchdbSession) { this.messages = _.extend({}, { missingCredentials: 'Username or password cannot be blank.', passwordsNotMatch: 'Passwords do not match.', - incorrectCredentials: 'Incorrect username or password.', loggedIn: 'You have been logged in.', adminCreated: 'CouchDB admin created', changePassword: 'Your password has been updated.' @@ -234,12 +245,7 @@ function (app, FauxtonAPI, CouchdbSession) { } }); - promise.fail(function (rsp) { - FauxtonAPI.addNotification({ - msg: 'Could not create admin. Reason' + rsp + '.', - type: 'error' - }); - }); + promise.fail(promiseErrorHandler); } }); @@ -264,18 +270,7 @@ function (app, FauxtonAPI, CouchdbSession) { FauxtonAPI.navigate('/'); }); - promise.fail(function (xhr, type, msg) { - if (arguments.length === 3) { - msg = FauxtonAPI.session.messages.incorrectCredentials; - } else { - msg = xhr; - } - - FauxtonAPI.addNotification({ - msg: msg, - type: 'error' - }); - }); + promise.fail(promiseErrorHandler); } }); @@ -302,16 +297,7 @@ function (app, FauxtonAPI, CouchdbSession) { that.$('#password-confirm').val(''); }); - promise.fail(function (xhr, error, msg) { - if (arguments.length < 3) { - msg = xhr; - } - - FauxtonAPI.addNotification({ - msg: xhr, - type: 'error' - }); - }); + promise.fail(promiseErrorHandler); } }); |