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

Fix undefined reference in http-api

Put the check for 'onprogress' within the check to see if req is
defined, because sometimes it isn't, apparently.
This commit is contained in:
David Baker
2017-03-23 15:38:15 +00:00
parent 62090ef119
commit 2c1e3416e3

View File

@@ -686,21 +686,22 @@ module.exports.MatrixHttpApi.prototype = {
handlerFn(err, response, body); handlerFn(err, response, body);
}, },
); );
// This will only work in a browser, where opts.request is the if (req) {
// `browser-request` import. Currently `request` does not support progress // This will only work in a browser, where opts.request is the
// updates - see https://github.com/request/request/pull/2346. // `browser-request` import. Currently `request` does not support progress
// `browser-request` returns an XHRHttpRequest which exposes `onprogress` // updates - see https://github.com/request/request/pull/2346.
if ('onprogress' in req) { // `browser-request` returns an XHRHttpRequest which exposes `onprogress`
req.onprogress = (e) => { if ('onprogress' in req) {
// Prevent the timeout from rejecting the deferred promise if progress is req.onprogress = (e) => {
// seen with the request // Prevent the timeout from rejecting the deferred promise if progress is
resetTimeout(); // seen with the request
}; resetTimeout();
} };
if (req && req.abort) { }
// FIXME: This is EVIL, but I can't think of a better way to expose // FIXME: This is EVIL, but I can't think of a better way to expose
// abort() operations on underlying HTTP requests :( // abort() operations on underlying HTTP requests :(
reqPromise.abort = req.abort.bind(req); if (req.abort) reqPromise.abort = req.abort.bind(req);
} }
} catch (ex) { } catch (ex) {
defer.reject(ex); defer.reject(ex);