Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unstable errcode support - MSC3848 #2534

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,8 @@ function getResponseContentType(response: XMLHttpRequest | IncomingMessage): Par
interface IErrorJson extends Partial<IUsageLimit> {
[key: string]: any; // extensible
errcode?: string;
// https://github.com/matrix-org/matrix-spec-proposals/pull/3848
"org.matrix.unstable.errcode"?: string;
error?: string;
}

Expand All @@ -1062,19 +1064,22 @@ interface IErrorJson extends Partial<IUsageLimit> {
* @constructor
* @param {Object} errorJson The Matrix error JSON returned from the homeserver.
* @prop {string} errcode The Matrix 'errcode' value, e.g. "M_FORBIDDEN".
* @prop {string} unstableErrorCode A possible unstable 'errcode' when a new error code is being introduced to the spec. e.g. "ORG.MATRIX.MSC3848.ALREADY_JOINED"
* @prop {string} name Same as MatrixError.errcode but with a default unknown string.
* @prop {string} message The Matrix 'error' value, e.g. "Missing token."
* @prop {Object} data The raw Matrix error JSON used to construct this object.
* @prop {number} httpStatus The numeric HTTP status code given
*/
export class MatrixError extends Error {
public readonly errcode: string;
public readonly unstableErrorCode: string;
public readonly data: IErrorJson;
public httpStatus?: number; // set by http-api

constructor(errorJson: IErrorJson = {}) {
super(`MatrixError: ${errorJson.errcode}`);
super(`MatrixError: ${errorJson["org.matrix.unstable.errcode"] ?? errorJson.errcode}`);
this.errcode = errorJson.errcode;
this.unstableErrorCode = errorJson["org.matrix.unstable.errcode"];
this.name = errorJson.errcode || "Unknown error code";
this.message = errorJson.error || "Unknown message";
this.data = errorJson;
Expand Down