Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getPlayerInfo again #850

Merged
merged 12 commits into from
Feb 13, 2025
11 changes: 5 additions & 6 deletions lib/users/getPlayerInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ function getPlayerInfo (userId) {

Promise.all(requests).then((promiseResponses) => {
const responses = promiseResponses.map(response => response.value)
const usersResponse = responses[0]
const userBody = usersResponse ? usersResponse.body : {}
const failedResponse = promiseResponses.find(presponse => presponse.status === 'rejected') || responses.find(response => !response || (!(response instanceof Array) && (response.statusCode !== 200 || !response.body)))
const userBody = responses[0]
const failedResponses = promiseResponses.filter(presponse => presponse.status === 'rejected')

if (userBody.isBanned) {
if (userBody?.isBanned) {
const joinDate = new Date(userBody.created)
const blurb = userBody.description
const isBanned = userBody.isBanned
Expand All @@ -53,8 +52,8 @@ function getPlayerInfo (userId) {
isBanned,
displayName
})
} else if (failedResponse) {
reject(new Error('User does not exist.'))
} else if (failedResponses) {
reject(new Error(failedResponses.map(r => r.reason).join('\n')))
} else {
const responseBodies = responses.map(res => res.body ?? res)
const oldNames = responses[4].map(nameObject => nameObject.name) || []
Expand Down
Loading