From 1c58cf1916170cb53470034082812794a878779c Mon Sep 17 00:00:00 2001 From: passion-27 Date: Sat, 18 Nov 2017 23:21:52 +0300 Subject: [PATCH] src: Improve default error logging of `polling_error`, `webhook_error` References: * BR: https://github.com/yagop/node-telegram-bot-api/issues/377 --- CHANGELOG.md | 6 +++++- src/errors.js | 6 ++++++ src/telegramPolling.js | 2 +- src/telegramWebHook.js | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c0a653..0d8af7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,15 @@ Added: friends e.g. `text`, `audio`, etc.) (#409) (by @jlsjonas, @GochoMugo) 1. Add support for Node.js v9 (by @GochoMugo) 1. Document *TelegramBot.errors*, *TelegramBot.messageTypes* (by @GochoMugo) -1. Fix game example (by @MCSH) Changed: 1. Update *TelegramBot#answerCallbackQuery()* signature (by @GochoMugo) +1. Improve default error logging of `polling_error` and `webhook_error` + +Fixed: + +1. Fix game example (by @MCSH) * * * diff --git a/src/errors.js b/src/errors.js index a4bffd3..5dd89e7 100644 --- a/src/errors.js +++ b/src/errors.js @@ -10,6 +10,12 @@ exports.BaseError = class BaseError extends Error { super(`${code}: ${message}`); this.code = code; } + toJSON() { + return { + code: this.code, + message: this.message, + }; + } }; diff --git a/src/telegramPolling.js b/src/telegramPolling.js index 54e3e89..0c43bd2 100644 --- a/src/telegramPolling.js +++ b/src/telegramPolling.js @@ -102,7 +102,7 @@ class TelegramBotPolling { if (this.bot.listeners('polling_error').length) { this.bot.emit('polling_error', err); } else { - console.error(err); // eslint-disable-line no-console + console.error('error: [polling_error] %j', err); // eslint-disable-line no-console } return null; }) diff --git a/src/telegramWebHook.js b/src/telegramWebHook.js index 2ca20a3..f7233b1 100644 --- a/src/telegramWebHook.js +++ b/src/telegramWebHook.js @@ -97,7 +97,7 @@ class TelegramBotWebHook { */ _error(error) { if (!this.bot.listeners('webhook_error').length) { - return console.error(error); // eslint-disable-line no-console + return console.error('error: [webhook_error] %j', error); // eslint-disable-line no-console } return this.bot.emit('webhook_error', error); }