Selaa lähdekoodia

handle/ignore partial auth error while fetching tweets

Mike L 2 vuotta sitten
vanhempi
commit
6ab9192bfd
2 muutettua tiedostoa jossa 15 lisäystä ja 3 poistoa
  1. 8 2
      dist/twitter.js
  2. 7 1
      src/twitter.ts

+ 8 - 2
dist/twitter.js

@@ -249,8 +249,14 @@ class default_1 {
         this.get = (type, targetId, params) => {
             const { since_id, max_results } = params;
             const getMore = (res) => {
-                if (res.errors && res.errors.length > 0)
-                    throw res.errors[0];
+                if (res.errors && res.errors.length > 0) {
+                    const [err] = res.errors;
+                    if (!res.data)
+                        throw err;
+                    if (err.title === 'Authorization Error') {
+                        logger.warn(`non-fatal error while querying ${type} with id ${targetId}, error: ${err.detail}`);
+                    }
+                }
                 if (!res.meta.next_token ||
                     utils_1.BigNumOps.compare(res.tweets.slice(-1)[0].id, since_id || '0') !== 1 ||
                     !since_id && res.meta.result_count >= max_results)

+ 7 - 1
src/twitter.ts

@@ -435,7 +435,13 @@ export default class {
   ) => {
     const {since_id, max_results} = (params as Twitter.TweetV2UserTimelineParams);
     const getMore = (res: Twitter.TweetUserTimelineV2Paginator | Twitter.TweetV2ListTweetsPaginator) => {
-      if (res.errors && res.errors.length > 0) throw res.errors[0];
+      if (res.errors && res.errors.length > 0) {
+        const [err] = res.errors;
+        if (!res.data) throw err;
+        if (err.title === 'Authorization Error') {
+          logger.warn(`non-fatal error while querying ${type} with id ${targetId}, error: ${err.detail}`);
+        }
+      }
       if (!res.meta.next_token ||                                               // at last page
         BigNumOps.compare(res.tweets.slice(-1)[0].id, since_id || '0') !== 1 || // at specified boundary
         !since_id && res.meta.result_count >= max_results                       // at specified max count