Skip to content

Commit

Permalink
readd failover if server does not handle access-token via header
Browse files Browse the repository at this point in the history
  • Loading branch information
krombel committed Jul 1, 2017
1 parent 59160a5 commit c6d2d4c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build": "babel -s -d lib src && rimraf dist && mkdir dist && browserify -d browser-index.js | exorcist dist/browser-matrix.js.map > dist/browser-matrix.js && uglifyjs -c -m -o dist/browser-matrix.min.js --source-map dist/browser-matrix.min.js.map --in-source-map dist/browser-matrix.js.map dist/browser-matrix.js",
"dist": "npm run build",
"watch": "watchify -d browser-index.js -o 'exorcist dist/browser-matrix.js.map > dist/browser-matrix.js' -v",
"lint": "eslint --max-warnings 112 src spec",
"lint": "eslint --max-warnings 110 src spec",
"prepublish": "npm run build && git rev-parse HEAD > git-revision.txt"
},
"repository": {
Expand Down
4 changes: 3 additions & 1 deletion src/http-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,16 @@ module.exports.MatrixHttpApi.prototype = {
const self = this;

requestPromise.catch(function(err) {
if (err.toString().indexOf("Error: CORS request rejected") != -1) {
if (err.errcode == 'M_MISSING_TOKEN' ||
err.toString().indexOf("Error: CORS request rejected") != -1) {
self.authorization_header_supported = false;
queryParams.access_token = opts.headers.Authorization.substr(7);
delete opts.headers.Authorization;
const secondPromise = self.request(
callback, method, path, queryParams, data, opts,
);
requestPromise.abort = secondPromise.abort;
return secondPromise;
}
if (err.errcode == 'M_UNKNOWN_TOKEN') {
self.event_emitter.emit("Session.logged_out");
Expand Down

0 comments on commit c6d2d4c

Please sign in to comment.