telebot
Version:
The easy way to write Telegram bots.
46 lines (45 loc) • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ERROR_TELEBOT_ALREADY_RUNNING = "Telebot is already running. Terminate instance for safety.";
exports.ERROR_TELEBOT_MAXIMUM_RETRY = "Maximum retries exceeded. Terminate instance for safety.";
class TeleBotError extends Error {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(error, data) {
super(error);
this.name = "TeleBotError";
this.message = error;
this.data = data || {};
}
}
exports.TeleBotError = TeleBotError;
class TelegramError extends Error {
constructor({ error_code, description, parameters }) {
super(`${error_code}: ${description}`);
this.name = "TelegramError";
this.code = error_code;
this.description = description;
this.parameters = parameters;
}
}
exports.TelegramError = TelegramError;
class TeleBotRequestError extends Error {
constructor(response) {
super(`${response.status} - ${response.statusText}`);
this.name = "TeleBotRequestError";
const { url, method, data } = response.config;
this.request = { url, method, data };
this.response = response.data;
}
}
exports.TeleBotRequestError = TeleBotRequestError;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function handleTelegramResponse(error) {
if (error.isAxiosError) {
const { response } = error;
if (response) {
return new TeleBotRequestError(response);
}
}
return error;
}
exports.handleTelegramResponse = handleTelegramResponse;