Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let json = {}
try {
const res = await client.get('/accounts/verify_credentials')
json = {
username: res.data.username,
accountId: res.data.id,
avatar: res.data.avatar
}
} catch (err) {
log.error(err)
log.info('Get new access token using refresh token...')
// If failed to fetch account, get new access token usign refresh token.
if (!account.refreshToken) {
throw new RefreshTokenDoesNotExist()
}
const token = await Mastodon.refreshToken(account.clientId, account.clientSecret, account.refreshToken, account.baseURL, proxy)
client = new Mastodon(token.access_token, account.baseURL + '/api/v1', 'Whalebird', proxy)
const res = await client.get('/accounts/verify_credentials')
json = {
username: res.data.username,
accountId: res.data.id,
avatar: res.data.avatar,
accessToken: token.accessToken,
refreshToken: token.refreshToken
}
}
return this.updateAccount(account._id!, json)
}