Correctly catch some errors.
This commit is contained in:
parent
6ff17d16f0
commit
25472bcfa6
@ -48,6 +48,8 @@ function makeStandaloneDeferred() {
|
|||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function noop() {}
|
||||||
|
|
||||||
function startsWith(string, target) {
|
function startsWith(string, target) {
|
||||||
return (string.lastIndexOf(target, 0) === 0);
|
return (string.lastIndexOf(target, 0) === 0);
|
||||||
}
|
}
|
||||||
@ -253,7 +255,10 @@ function resetSession() {
|
|||||||
this._credentials = makeStandaloneDeferred();
|
this._credentials = makeStandaloneDeferred();
|
||||||
|
|
||||||
// The promise from the previous session needs to be rejected.
|
// The promise from the previous session needs to be rejected.
|
||||||
if (this._session && !this._session.isPending()) {
|
if (this._session && this._session.isPending()) {
|
||||||
|
// Ensure Bluebird does not mark this rejection as unhandled.
|
||||||
|
this._session.catch(noop);
|
||||||
|
|
||||||
this._session.reject();
|
this._session.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,16 +279,21 @@ function signIn() {
|
|||||||
'session.signInWithPassword',
|
'session.signInWithPassword',
|
||||||
credentials
|
credentials
|
||||||
);
|
);
|
||||||
}).then(function (user) {
|
}).then(
|
||||||
this.user = user;
|
function (user) {
|
||||||
|
this.user = user;
|
||||||
|
|
||||||
this._api.call('xo.getAllObjects').bind(this).then(function (objects) {
|
this._api.call('xo.getAllObjects').bind(this).then(function (objects) {
|
||||||
this.objects.clear();
|
this.objects.clear();
|
||||||
this.objects.setMultiple(objects);
|
this.objects.setMultiple(objects);
|
||||||
});
|
}).catch(noop); // Ignore any errors.
|
||||||
|
|
||||||
session.resolve();
|
session.resolve();
|
||||||
});
|
},
|
||||||
|
function (error) {
|
||||||
|
session.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// High level interface to Xo.
|
// High level interface to Xo.
|
||||||
@ -377,6 +387,8 @@ Xo.prototype.signOut = function () {
|
|||||||
|
|
||||||
resetSession.call(this);
|
resetSession.call(this);
|
||||||
|
|
||||||
|
signIn.call(this);
|
||||||
|
|
||||||
return promise || Bluebird.resolve();
|
return promise || Bluebird.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user