You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-18 05:42:00 +03:00
turn HTTP exceptions into errbacks or rejected deferreds rather than bubbling them up and expecting the app to have try blocks eeeeeeeeeverywhere
This commit is contained in:
@@ -378,23 +378,36 @@ module.exports.MatrixHttpApi.prototype = {
|
||||
}
|
||||
}
|
||||
var defer = q.defer();
|
||||
this.opts.request(
|
||||
{
|
||||
uri: uri,
|
||||
method: method,
|
||||
withCredentials: false,
|
||||
qs: queryParams,
|
||||
body: data,
|
||||
json: true,
|
||||
_matrix_opts: this.opts
|
||||
},
|
||||
requestCallback(defer, callback, this.opts.onlyData)
|
||||
);
|
||||
try {
|
||||
this.opts.request(
|
||||
{
|
||||
uri: uri,
|
||||
method: method,
|
||||
withCredentials: false,
|
||||
qs: queryParams,
|
||||
body: data,
|
||||
json: true,
|
||||
_matrix_opts: this.opts
|
||||
},
|
||||
requestCallback(defer, callback, this.opts.onlyData)
|
||||
);
|
||||
}
|
||||
catch (ex) {
|
||||
defer.reject(ex);
|
||||
if (callback) callback(ex);
|
||||
}
|
||||
return defer.promise;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Returns a callback that can be invoked by an HTTP request on completion,
|
||||
* that will either resolve or reject the given defer as well as invoke the
|
||||
* given userDefinedCallback (if any).
|
||||
*
|
||||
* If onlyData is true, the defer/callback is invoked with the body of the
|
||||
* response, otherwise the result code.
|
||||
*/
|
||||
var requestCallback = function(defer, userDefinedCallback, onlyData) {
|
||||
userDefinedCallback = userDefinedCallback || function() {};
|
||||
|
||||
|
Reference in New Issue
Block a user