You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Add MatrixError class. More jsdoc voodoo to get things looking right.
This commit is contained in:
@@ -189,10 +189,27 @@ var requestCallback = function(userDefinedCallback) {
|
||||
return userDefinedCallback(err);
|
||||
}
|
||||
if (response.statusCode >= 400) {
|
||||
return userDefinedCallback(body);
|
||||
return userDefinedCallback(new Error(body));
|
||||
}
|
||||
else {
|
||||
userDefinedCallback(null, body);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Construct a Matrix error. This is a JavaScript Error with additional
|
||||
* information specific to the standard Matrix error response.
|
||||
* @constructor
|
||||
* @param {Object} errorJson The Matrix error JSON returned from the homeserver.
|
||||
* @prop {string} name The Matrix 'errcode' value, e.g. "M_FORBIDDEN".
|
||||
* @prop {string} message The Matrix 'error' value, e.g. "Missing token."
|
||||
* @prop {Object} data The raw Matrix error JSON used to construct this object.
|
||||
*/
|
||||
module.exports.MatrixError = function MatrixError(errorJson) {
|
||||
this.name = errorJson.errcode || "Unknown error code";
|
||||
this.message = errorJson.error || "Unknown message";
|
||||
this.data = errorJson;
|
||||
}
|
||||
module.exports.MatrixError.prototype = Object.create(Error.prototype);
|
||||
module.exports.MatrixError.prototype.constructor = MatrixError;
|
||||
Reference in New Issue
Block a user