Skip to content

Commit 5e89fe5

Browse files
authored
feat: fulfilled twitter promise (#133)
avoid throw a global error
1 parent 6a5e0d6 commit 5e89fe5

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

packages/metascraper-media-provider/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"lodash": "~4.17.10",
1818
"memoize-one": "~4.0.3",
1919
"memoize-token": "~1.1.0",
20+
"p-reflect": "~1.0.0",
2021
"tunnel": "0.0.6",
2122
"youtube-dl": "~1.12.2"
2223
},

packages/metascraper-media-provider/src/get-media/twitter-info.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const memoizeToken = require('memoize-token')
44
const { get, chain } = require('lodash')
5+
const pReflect = require('p-reflect')
56
const tunnel = require('tunnel')
67
const { URL } = require('url')
78
const got = require('got')
@@ -55,13 +56,17 @@ const getTwitterInfo = ({ getToken }) => async url => {
5556
const tweetId = getTweetId(url)
5657
const apiUrl = `https://api.twitter.com/2/timeline/conversation/${tweetId}.json?tweet_mode=extended`
5758
const guestToken = await getToken(url)
58-
const { body } = await got(apiUrl, {
59-
json: true,
60-
headers: {
61-
authorization: TWITTER_BEARER_TOKEN,
62-
'x-guest-token': guestToken
63-
}
64-
})
59+
const res = await pReflect(
60+
got(apiUrl, {
61+
json: true,
62+
headers: {
63+
authorization: TWITTER_BEARER_TOKEN,
64+
'x-guest-token': guestToken
65+
}
66+
})
67+
)
68+
69+
const body = get(res, 'value.body')
6570

6671
const id = get(
6772
body,

0 commit comments

Comments
 (0)