feat(twitter): skip invalid token
This commit is contained in:
parent
292471ec23
commit
3ce18dff48
|
|
@ -119,17 +119,22 @@ export const twitterGot = async (url, params) => {
|
|||
},
|
||||
dispatcher: dispatchers[token].agent,
|
||||
onResponse: async ({ response }) => {
|
||||
if (response.status === 403 || response.status === 401) {
|
||||
logger.debug(`Delete twitter cookie for token ${token}`);
|
||||
if (response.status === 403 || response.status === 401 || response.status === 429) {
|
||||
const newCookie = await login({
|
||||
username: config.twitter.username?.[index],
|
||||
password: config.twitter.password?.[index],
|
||||
authenticationSecret: config.twitter.authenticationSecret?.[index],
|
||||
});
|
||||
if (newCookie) {
|
||||
await cache.set(`twitter:cookie:${token}`, newCookie, config.cache.contentExpire);
|
||||
logger.debug(`Reset twitter cookie for token ${token}`);
|
||||
} else {
|
||||
config.twitter.authToken?.splice(index, 1);
|
||||
config.twitter.username?.splice(index, 1);
|
||||
config.twitter.password?.splice(index, 1);
|
||||
await cache.set(`twitter:cookie:${token}`, '', config.cache.contentExpire);
|
||||
logger.debug(`Delete twitter cookie for token ${token}, remaining tokens: ${config.twitter.authToken?.length}`);
|
||||
}
|
||||
await cache.set(`twitter:cookie:${token}`, newCookie || '', config.cache.contentExpire);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue