twitter 获取access token出错时, 打印更详细的日志

This commit is contained in:
CounterFire2023 2024-04-23 10:15:28 +08:00
parent 3691d000da
commit b8b8ec4dfc

View File

@ -1,5 +1,6 @@
const consumerKey = process.env.TWITTER_CLIENT_ID
const consumerSecret = process.env.TWITTER_CLIENT_SECRET
import logger from 'logger/logger'
import { OAuth } from 'oauth'
import { promisify } from 'util'
@ -87,9 +88,12 @@ export async function getOAuthAccessTokenWith({
oauthRequestTokenSecret,
oauthVerifier,
function (error, oauthAccessToken, oauthAccessTokenSecret, results) {
return error
? reject(new Error('Error getting OAuth access token'))
: resolve({ oauthAccessToken, oauthAccessTokenSecret, results })
if (error) {
logger.error(error)
reject(new Error('Error getting OAuth access token'))
} else {
resolve({ oauthAccessToken, oauthAccessTokenSecret, results })
}
},
)
})
@ -97,9 +101,12 @@ export async function getOAuthAccessTokenWith({
export async function getOAuthRequestToken() {
return new Promise((resolve, reject) => {
oauthConsumer.getOAuthRequestToken(function (error, oauthRequestToken, oauthRequestTokenSecret, results) {
return error
? reject(new Error('Error getting OAuth request token'))
: resolve({ oauthRequestToken, oauthRequestTokenSecret, results })
if (error) {
logger.error(error)
reject(new Error('Error getting OAuth request token'))
} else {
resolve({ oauthRequestToken, oauthRequestTokenSecret, results })
}
})
})
}