Sfoglia il codice sorgente

add another case for triggering re-login

Mike L 3 anni fa
parent
commit
efa3c9efb8
2 ha cambiato i file con 9 aggiunte e 7 eliminazioni
  1. 4 3
      dist/twitter.js
  2. 5 4
      src/twitter.ts

+ 4 - 3
dist/twitter.js

@@ -189,7 +189,7 @@ class default_1 {
             }
             return this.client.user.searchExact(username)
                 .catch((error) => {
-                if (error instanceof instagram_private_api_1.IgLoginRequiredError) {
+                if (error instanceof instagram_private_api_1.IgLoginRequiredError || error instanceof instagram_private_api_1.IgCookieNotFoundError) {
                     logger.warn('login required, logging in again...');
                     return this.session.login().then(() => this.client.user.searchExact(username));
                 }
@@ -266,7 +266,7 @@ class default_1 {
                     }
                     logger.warn(`error while fetching stories for all: ${JSON.stringify(error.cause)}`);
                 }
-                else if (error instanceof instagram_private_api_1.IgLoginRequiredError) {
+                else if (error instanceof instagram_private_api_1.IgLoginRequiredError || error instanceof instagram_private_api_1.IgCookieNotFoundError) {
                     logger.warn('login required, logging in again...');
                     this.session.login().then(this.workForAll);
                 }
@@ -425,8 +425,9 @@ class default_1 {
                     logger.warn(`error while fetching stories for ${rawUserName}: ${JSON.stringify(error.cause)}`);
                     this.bot.sendTo(receiver, `获取 Stories 时出现错误:原因: ${error.cause}`);
                 }
-                else if (error instanceof instagram_private_api_1.IgLoginRequiredError) {
+                else if (error instanceof instagram_private_api_1.IgLoginRequiredError || error instanceof instagram_private_api_1.IgCookieNotFoundError) {
                     logger.warn('login required, logging in again...');
+                    this.bot.sendTo(receiver, '等待登陆中,稍后会处理请求,请稍候……');
                     this.session.login().then(() => exports.sendAllStories(rawUserName, receiver, startIndex, count));
                 }
                 else {

+ 5 - 4
src/twitter.ts

@@ -7,7 +7,7 @@ import { promisify } from 'util';
 
 import {
   IgApiClient,
-  IgClientError, IgExactUserNotFoundError, IgLoginTwoFactorRequiredError, IgLoginRequiredError, IgNetworkError,
+  IgClientError, IgCookieNotFoundError, IgExactUserNotFoundError, IgLoginTwoFactorRequiredError, IgLoginRequiredError, IgNetworkError,
   ReelsMediaFeedResponseItem, UserFeedResponseUser
 } from 'instagram-private-api';
 import { RequestError } from 'request-promise/errors';
@@ -286,8 +286,9 @@ export default class {
             }
             logger.warn(`error while fetching stories for ${rawUserName}: ${JSON.stringify(error.cause)}`);
             this.bot.sendTo(receiver, `获取 Stories 时出现错误:原因: ${error.cause}`);
-          } else if (error instanceof IgLoginRequiredError) {
+          } else if (error instanceof IgLoginRequiredError || error instanceof IgCookieNotFoundError) {
             logger.warn('login required, logging in again...');
+            this.bot.sendTo(receiver, '等待登陆中,稍后会处理请求,请稍候……');
             this.session.login().then(() => sendAllStories(rawUserName, receiver, startIndex, count));
           } else {
             logger.error(`unhandled error while fetching stories for ${rawUserName}: ${error}`);
@@ -319,7 +320,7 @@ export default class {
     }
     return this.client.user.searchExact(username)
       .catch((error: IgClientError) => {
-        if (error instanceof IgLoginRequiredError) {
+        if (error instanceof IgLoginRequiredError || error instanceof IgCookieNotFoundError) {
           logger.warn('login required, logging in again...');
           return this.session.login().then(() => this.client.user.searchExact(username));
         } else throw error;
@@ -427,7 +428,7 @@ export default class {
             return this.session.login().then(this.workForAll);
           }
           logger.warn(`error while fetching stories for all: ${JSON.stringify(error.cause)}`);
-        } else if (error instanceof IgLoginRequiredError) {
+        } else if (error instanceof IgLoginRequiredError || error instanceof IgCookieNotFoundError) {
           logger.warn('login required, logging in again...');
           this.session.login().then(this.workForAll);
         } else {