@tgsnake/core
Version:
Pure Telegram MTProto library for nodejs
112 lines (111 loc) • 5.14 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.CDNFileHashMismatch = exports.SecurityCheckMismatch = exports.SecurityError = exports.BadMsgNotification = exports.NotAFunctionClass = exports.TimeoutError = exports.UnknownError = exports.RPCError = exports.FileErrors = exports.SecretChatError = exports.WSError = exports.ClientError = exports.Exceptions = void 0;
exports.Exceptions = __importStar(require("./exceptions/index.js"));
exports.ClientError = __importStar(require("./Client.js"));
exports.WSError = __importStar(require("./WebSocket.js"));
exports.SecretChatError = __importStar(require("./SecretChat.js"));
exports.FileErrors = __importStar(require("./File.js"));
var RpcError_js_1 = require("./RpcError.js");
Object.defineProperty(exports, "RPCError", { enumerable: true, get: function () { return RpcError_js_1.RPCError; } });
Object.defineProperty(exports, "UnknownError", { enumerable: true, get: function () { return RpcError_js_1.UnknownError; } });
const Base_js_1 = require("./Base.js");
class TimeoutError extends Base_js_1.BaseError {
timeout;
constructor(timeout) {
super();
this.message = `Running timeout after ${timeout} ms`;
this.timeout = timeout;
this.description = `The function is running too long, until it reaches the time limit that has been given.`;
}
}
exports.TimeoutError = TimeoutError;
class NotAFunctionClass extends Base_js_1.BaseError {
message = '{value} is not a function.';
description = "The provided class {value} is not a function constructor, can't sending request with that class.";
constructor(className) {
super();
this.message = this.message.replace('{value}', className);
this.description = this.description.replace('{value}', className);
}
}
exports.NotAFunctionClass = NotAFunctionClass;
class BadMsgNotification extends Base_js_1.BaseError {
constructor(code) {
const description = {
16: 'The msg_id is too low, the client time has to be synchronized.',
17: 'The msg_id is too high, the client time has to be synchronized.',
18: 'Incorrect two lower order of the msg_id bits, the server expects the client message\nmsg_id to be divisible by 4.',
19: 'The container msg_id is the same as the msg_id of a previously received message.',
20: 'The message is too old, it cannot be verified by the server.',
32: 'The msg_seqno is too low.',
33: 'The msg_seqno is too high.',
34: 'An even msg_seqno was expected, but an odd one was received.',
35: 'An odd msg_seqno was expected, but an even one was received.',
48: 'Incorrect server salt.',
64: 'Invalid container.',
};
super(`[${code}] ${description[code] ?? 'Unknown Error'}`);
}
}
exports.BadMsgNotification = BadMsgNotification;
class SecurityError extends Base_js_1.BaseError {
constructor(description) {
super();
this.description = description;
}
static check(cond, description) {
if (!cond)
throw new SecurityError(description);
}
}
exports.SecurityError = SecurityError;
class SecurityCheckMismatch extends SecurityError {
message = 'A security check mismatch has occurred.';
static check(cond, description) {
if (!cond)
throw new SecurityCheckMismatch(description);
}
}
exports.SecurityCheckMismatch = SecurityCheckMismatch;
class CDNFileHashMismatch extends SecurityError {
message = 'A CDN file hash mismatch has occurred.';
static check(cond, description) {
if (!cond)
throw new CDNFileHashMismatch(description);
}
}
exports.CDNFileHashMismatch = CDNFileHashMismatch;