You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
cleanup: use class for MatrixError
this way we get stacktraces as well
This commit is contained in:
@@ -892,12 +892,13 @@ function getResponseContentType(response) {
|
|||||||
* @prop {Object} data The raw Matrix error JSON used to construct this object.
|
* @prop {Object} data The raw Matrix error JSON used to construct this object.
|
||||||
* @prop {integer} httpStatus The numeric HTTP status code given
|
* @prop {integer} httpStatus The numeric HTTP status code given
|
||||||
*/
|
*/
|
||||||
export function MatrixError(errorJson) {
|
export class MatrixError extends Error {
|
||||||
errorJson = errorJson || {};
|
constructor(errorJson) {
|
||||||
this.errcode = errorJson.errcode;
|
errorJson = errorJson || {};
|
||||||
this.name = errorJson.errcode || "Unknown error code";
|
super(`MatrixError: ${errorJson.errcode}`);
|
||||||
this.message = errorJson.error || "Unknown message";
|
this.errcode = errorJson.errcode;
|
||||||
this.data = errorJson;
|
this.name = errorJson.errcode || "Unknown error code";
|
||||||
|
this.message = errorJson.error || "Unknown message";
|
||||||
|
this.data = errorJson;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MatrixError.prototype = Object.create(Error.prototype);
|
|
||||||
MatrixError.prototype.constructor = MatrixError;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user