1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Include the error object when raising Session.logged_out

Note: The `call` argument previously defined in the SDK was never actually populated, and appears to be a documentation error when the definition was copied from `Call.incoming` directly above it.
This commit is contained in:
Travis Ralston
2019-07-03 16:42:33 -06:00
parent 2cdbc9f4db
commit 3aa2bf8a76
3 changed files with 25 additions and 4 deletions

View File

@@ -302,11 +302,32 @@ describe("MatrixClient events", function() {
}); });
it("should emit Session.logged_out on M_UNKNOWN_TOKEN", function() { it("should emit Session.logged_out on M_UNKNOWN_TOKEN", function() {
httpBackend.when("GET", "/sync").respond(401, { errcode: 'M_UNKNOWN_TOKEN' }); const error = { errcode: 'M_UNKNOWN_TOKEN' };
httpBackend.when("GET", "/sync").respond(401, error);
let sessionLoggedOutCount = 0; let sessionLoggedOutCount = 0;
client.on("Session.logged_out", function(event, member) { client.on("Session.logged_out", function(errObj) {
sessionLoggedOutCount++; sessionLoggedOutCount++;
expect(errObj).toMatchObject(error);
});
client.startClient();
return httpBackend.flushAllExpected().then(function() {
expect(sessionLoggedOutCount).toEqual(
1, "Session.logged_out fired wrong number of times",
);
});
});
it("should emit Session.logged_out on M_UNKNOWN_TOKEN (soft logout)", function() {
const error = { errcode: 'M_UNKNOWN_TOKEN', soft_logout: true };
httpBackend.when("GET", "/sync").respond(401, error);
let sessionLoggedOutCount = 0;
client.on("Session.logged_out", function(errObj) {
sessionLoggedOutCount++;
expect(errObj).toMatchObject(error);
}); });
client.startClient(); client.startClient();

View File

@@ -4555,7 +4555,7 @@ module.exports.CRYPTO_ENABLED = CRYPTO_ENABLED;
* when then login session can be renewed by using a refresh token. * when then login session can be renewed by using a refresh token.
* @event module:client~MatrixClient#"Session.logged_out" * @event module:client~MatrixClient#"Session.logged_out"
* @example * @example
* matrixClient.on("Session.logged_out", function(call){ * matrixClient.on("Session.logged_out", function(errorObj){
* // show the login screen * // show the login screen
* }); * });
*/ */

View File

@@ -470,7 +470,7 @@ module.exports.MatrixHttpApi.prototype = {
const self = this; const self = this;
requestPromise.catch(function(err) { requestPromise.catch(function(err) {
if (err.errcode == 'M_UNKNOWN_TOKEN') { if (err.errcode == 'M_UNKNOWN_TOKEN') {
self.event_emitter.emit("Session.logged_out"); self.event_emitter.emit("Session.logged_out", err);
} else if (err.errcode == 'M_CONSENT_NOT_GIVEN') { } else if (err.errcode == 'M_CONSENT_NOT_GIVEN') {
self.event_emitter.emit( self.event_emitter.emit(
"no_consent", "no_consent",