Browse Source

fix handling errors of failed delivery

Mike L 3 years ago
parent
commit
b3dbb7f386
4 changed files with 9 additions and 14 deletions
  1. 2 3
      dist/koishi.js
  2. 2 4
      dist/twitter.js
  3. 2 3
      src/koishi.ts
  4. 3 4
      src/twitter.ts

+ 2 - 3
dist/koishi.js

@@ -106,9 +106,8 @@ class default_1 {
             logger.info(`pushing data to ${JSON.stringify(subscriber.chatID)} was successful, response: ${response}`);
         })
             .catch(reason => {
-            reason = exports.Message.ellipseBase64(reason);
-            logger.error(`error pushing data to ${JSON.stringify(subscriber.chatID)}, reason: ${reason}`);
-            throw Error(reason);
+            logger.error(exports.Message.ellipseBase64(`error pushing data to ${JSON.stringify(subscriber.chatID)}, reason: ${reason}`));
+            throw reason instanceof Error ? reason : Error(reason);
         });
         this.initBot = () => {
             this.app = new koishi_1.App({

+ 2 - 4
dist/twitter.js

@@ -14,7 +14,6 @@ const fs = require("fs");
 const path = require("path");
 const Twitter = require("twitter");
 const loggers_1 = require("./loggers");
-const koishi_1 = require("./koishi");
 const utils_1 = require("./utils");
 const webshot_1 = require("./webshot");
 class ScreenNameNormalizer {
@@ -142,14 +141,13 @@ class default_1 {
         };
         this.sendTweets = (source, ...to) => (msg, text, author) => {
             to.forEach(subscriber => {
-                logger.info(`pushing data${source ? ` of ${koishi_1.Message.ellipseBase64(source)}` : ''} to ${JSON.stringify(subscriber)}`);
+                logger.info(`pushing data${source ? ` of ${source}` : ''} to ${JSON.stringify(subscriber)}`);
                 retryOnError(() => this.bot.sendTo(subscriber, msg), (_, count, terminate) => {
                     if (count <= maxTrials) {
                         logger.warn(`retry sending to ${subscriber.chatID} for the ${ordinal(count)} time...`);
                     }
                     else {
-                        logger.warn(`${count - 1} consecutive failures while sending` +
-                            'message chain, trying plain text instead...');
+                        logger.warn(`${count - 1} consecutive failures while sending message chain, trying plain text instead...`);
                         terminate(this.bot.sendTo(subscriber, author + text));
                     }
                 });

+ 2 - 3
src/koishi.ts

@@ -122,9 +122,8 @@ export default class {
       logger.info(`pushing data to ${JSON.stringify(subscriber.chatID)} was successful, response: ${response}`);
     })
     .catch(reason => {
-      reason = Message.ellipseBase64(reason);
-      logger.error(`error pushing data to ${JSON.stringify(subscriber.chatID)}, reason: ${reason}`);
-      throw Error(reason);
+      logger.error(Message.ellipseBase64(`error pushing data to ${JSON.stringify(subscriber.chatID)}, reason: ${reason}`));
+      throw reason instanceof Error ? reason : Error(reason);
     });
 
   private initBot = () => {

+ 3 - 4
src/twitter.ts

@@ -4,7 +4,7 @@ import * as Twitter from 'twitter';
 import TwitterTypes from 'twitter-d';
 
 import { getLogger } from './loggers';
-import QQBot, { Message } from './koishi';
+import QQBot from './koishi';
 import { chainPromises, BigNumOps } from './utils';
 import Webshot from './webshot';
 
@@ -276,15 +276,14 @@ export default class {
 
   private sendTweets = (source?: string, ...to: IChat[]) => (msg: string, text: string, author: string) => {
     to.forEach(subscriber => {
-      logger.info(`pushing data${source ? ` of ${Message.ellipseBase64(source)}` : ''} to ${JSON.stringify(subscriber)}`);
+      logger.info(`pushing data${source ? ` of ${source}` : ''} to ${JSON.stringify(subscriber)}`);
       retryOnError(
         () => this.bot.sendTo(subscriber, msg),
         (_, count, terminate: (doNothing: Promise<void>) => void) => {
           if (count <= maxTrials) {
             logger.warn(`retry sending to ${subscriber.chatID} for the ${ordinal(count)} time...`);
           } else {
-            logger.warn(`${count - 1} consecutive failures while sending` +
-            'message chain, trying plain text instead...');
+            logger.warn(`${count - 1} consecutive failures while sending message chain, trying plain text instead...`);
             terminate(this.bot.sendTo(subscriber, author + text));
           }
         });