2026-09-13 14:14:38 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
|
value: true
|
|
|
|
|
});
|
|
|
|
|
exports.MatrixError = exports.HTTPError = exports.ConnectionError = void 0;
|
|
|
|
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
2026-09-12 23:57:45 -04:00
|
|
|
/*
|
2026-09-13 14:14:38 -04:00
|
|
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
2026-09-12 23:57:45 -04:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct a generic HTTP error. This is a JavaScript Error with additional information
|
|
|
|
|
* specific to HTTP responses.
|
|
|
|
|
* @param msg - The error message to include.
|
|
|
|
|
* @param httpStatus - The HTTP response status code.
|
|
|
|
|
*/
|
2026-09-13 14:14:38 -04:00
|
|
|
class HTTPError extends Error {
|
|
|
|
|
constructor(msg, httpStatus) {
|
2026-09-12 23:57:45 -04:00
|
|
|
super(msg);
|
|
|
|
|
this.httpStatus = httpStatus;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-13 14:14:38 -04:00
|
|
|
exports.HTTPError = HTTPError;
|
|
|
|
|
class MatrixError extends HTTPError {
|
2026-09-12 23:57:45 -04:00
|
|
|
/**
|
|
|
|
|
* Construct a Matrix error. This is a JavaScript Error with additional
|
|
|
|
|
* information specific to the standard Matrix error response.
|
|
|
|
|
* @param errorJson - The Matrix error JSON returned from the homeserver.
|
|
|
|
|
* @param httpStatus - The numeric HTTP status code given
|
|
|
|
|
*/
|
2026-09-13 14:14:38 -04:00
|
|
|
constructor(errorJson = {}, httpStatus, url, event) {
|
2026-09-12 23:57:45 -04:00
|
|
|
let message = errorJson.error || "Unknown message";
|
|
|
|
|
if (httpStatus) {
|
|
|
|
|
message = `[${httpStatus}] ${message}`;
|
|
|
|
|
}
|
|
|
|
|
if (url) {
|
|
|
|
|
message = `${message} (${url})`;
|
|
|
|
|
}
|
2026-09-13 14:14:38 -04:00
|
|
|
super(`MatrixError: ${message}`, httpStatus);
|
|
|
|
|
this.httpStatus = httpStatus;
|
2026-09-12 23:57:45 -04:00
|
|
|
this.url = url;
|
|
|
|
|
this.event = event;
|
2026-09-13 14:14:38 -04:00
|
|
|
// The Matrix 'errcode' value, e.g. "M_FORBIDDEN".
|
|
|
|
|
(0, _defineProperty2.default)(this, "errcode", void 0);
|
|
|
|
|
// The raw Matrix error JSON used to construct this object.
|
|
|
|
|
(0, _defineProperty2.default)(this, "data", void 0);
|
2026-09-12 23:57:45 -04:00
|
|
|
this.errcode = errorJson.errcode;
|
|
|
|
|
this.name = errorJson.errcode || "Unknown error code";
|
|
|
|
|
this.data = errorJson;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct a ConnectionError. This is a JavaScript Error indicating
|
|
|
|
|
* that a request failed because of some error with the connection, either
|
|
|
|
|
* CORS was not correctly configured on the server, the server didn't response,
|
|
|
|
|
* the request timed out, or the internet connection on the client side went down.
|
|
|
|
|
*/
|
2026-09-13 14:14:38 -04:00
|
|
|
exports.MatrixError = MatrixError;
|
|
|
|
|
class ConnectionError extends Error {
|
2026-09-12 23:57:45 -04:00
|
|
|
constructor(message, cause) {
|
|
|
|
|
super(message + (cause ? `: ${cause.message}` : ""));
|
|
|
|
|
}
|
|
|
|
|
get name() {
|
|
|
|
|
return "ConnectionError";
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-13 14:14:38 -04:00
|
|
|
exports.ConnectionError = ConnectionError;
|
2026-09-12 23:57:45 -04:00
|
|
|
//# sourceMappingURL=errors.js.map
|