|
@@ -39,6 +39,9 @@ const linkBuilder = (config: ReturnType<typeof parseLink>): string => {
|
|
|
|
|
|
export {linkBuilder, parseLink};
|
|
|
|
|
|
+const igErrorIsAuthError = (error: IgClientError) =>
|
|
|
+ / 40\d/.test(error.message) || error instanceof IgLoginRequiredError || error instanceof IgCookieNotFoundError;
|
|
|
+
|
|
|
interface IWorkerOption {
|
|
|
sessionLockfile: string;
|
|
|
credentials: [string, string];
|
|
@@ -303,7 +306,7 @@ export default class {
|
|
|
}
|
|
|
logger.warn(`error while fetching stories for ${rawUserName}: ${JSON.stringify(error.cause)}`);
|
|
|
reply(`获取 Stories 时出现错误:原因: ${error.cause}`);
|
|
|
- } else if (error instanceof IgLoginRequiredError || error instanceof IgCookieNotFoundError) {
|
|
|
+ } else if (igErrorIsAuthError(error)) {
|
|
|
logger.warn('login required, logging in again...');
|
|
|
reply('等待登录中,稍后会处理请求,请稍候……');
|
|
|
this.session.login().then(retryAction);
|
|
@@ -399,7 +402,7 @@ export default class {
|
|
|
public queryUserObject = (userName: string) =>
|
|
|
this.client.user.searchExact(userName)
|
|
|
.catch((error: IgClientError) => {
|
|
|
- if (error instanceof IgLoginRequiredError || error instanceof IgCookieNotFoundError) {
|
|
|
+ if (igErrorIsAuthError(error)) {
|
|
|
logger.warn('login required, logging in again...');
|
|
|
return this.session.login().then(() => this.client.user.searchExact(userName));
|
|
|
} else throw error;
|
|
@@ -537,7 +540,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 || error instanceof IgCookieNotFoundError) {
|
|
|
+ } else if (igErrorIsAuthError(error)) {
|
|
|
logger.warn('login required, logging in again...');
|
|
|
this.session.login().then(this.workForAll);
|
|
|
} else {
|