Selaa lähdekoodia

fix uncatched api errors, fix typing error

Mike L 3 vuotta sitten
vanhempi
commit
05dc9fc2d4
4 muutettua tiedostoa jossa 27 lisäystä ja 19 poistoa
  1. 5 6
      dist/main.js
  2. 8 4
      dist/twitter.js
  3. 5 6
      src/main.ts
  4. 9 3
      src/twitter.ts

+ 5 - 6
dist/main.js

@@ -73,12 +73,11 @@ optionalFields.forEach(key => {
         config[key] = `${config.ig_username}.${key.replace('_lockfile', '.lock')}`;
     }
 });
-(k => {
-    if (!config[k] || config[k] < 2048 || config[k] > 65536) {
-        logger.warn(`invalid value of config.${k}, use ${exampleConfig[k]} as default`);
-        config[k] = exampleConfig[k];
-    }
-})('ig_2fa_code_receiver_port');
+const k = 'ig_2fa_code_receiver_port';
+if (!config[k] || config[k] < 2048 || config[k] > 65536) {
+    logger.warn(`invalid value of config.${k}, use ${exampleConfig[k]} as default`);
+    config[k] = exampleConfig[k];
+}
 loggers_1.setLogLevels(config.loglevel);
 let lock;
 if (fs.existsSync(path.resolve(config.lockfile))) {

+ 8 - 4
dist/twitter.js

@@ -323,10 +323,14 @@ class default_1 {
             const currentFeed = lock.feed[lock.workon];
             const promise = new Promise(resolve => {
                 const match = /https:\/\/www\.instagram\.com\/([^\/]+)/.exec(currentFeed);
-                if (match) {
-                    resolve(this.queryUserMedia(match[1], this.lock.threads[currentFeed].offset));
-                }
-                resolve([]);
+                if (!match)
+                    resolve([]);
+                this.queryUserMedia(match[1], this.lock.threads[currentFeed].offset)
+                    .then(resolve)
+                    .catch((error) => {
+                    console.error(`error scraping media off profile page of ${match[1]}, error: ${error}`);
+                    resolve([]);
+                });
             });
             promise.then((mediaItems) => {
                 const currentThread = lock.threads[currentFeed];

+ 5 - 6
src/main.ts

@@ -87,12 +87,11 @@ optionalFields.forEach(key => {
   }
 });
 
-(k => {
-  if (!config[k] || config[k] < 2048 || config[k] > 65536) {
-    logger.warn(`invalid value of config.${k}, use ${exampleConfig[k]} as default`);
-    config[k] = exampleConfig[k];
-  }
-})('ig_2fa_code_receiver_port');
+const k = 'ig_2fa_code_receiver_port';
+if (!config[k] || config[k] < 2048 || config[k] > 65536) {
+  logger.warn(`invalid value of config.${k}, use ${exampleConfig[k]} as default`);
+  config[k] = exampleConfig[k];
+}
 
 setLogLevels(config.loglevel);
 

+ 9 - 3
src/twitter.ts

@@ -486,10 +486,16 @@ export default class {
 
     const promise = new Promise<LazyMediaItem[]>(resolve => {
       const match = /https:\/\/www\.instagram\.com\/([^\/]+)/.exec(currentFeed);
-      if (match) {
-        resolve(this.queryUserMedia(match[1], this.lock.threads[currentFeed].offset));
+      if (!match) {
+        logger.error(`current feed "${currentFeed}" is invalid, please remove this feed manually`);
+        return resolve([]);
       }
-      resolve([]);
+      this.queryUserMedia(match[1], this.lock.threads[currentFeed].offset)
+        .then(resolve)
+        .catch((error: Error) => {
+          logger.error(`error scraping media off profile page of ${match[1]}, error: ${error}`);
+          resolve([]);
+        });
     });
 
     promise.then((mediaItems: LazyMediaItem[]) => {