gigobyte / HLTV

The unofficial HLTV Node.js API
MIT License
397 stars 107 forks source link

getPlayerStats returns an unhandled promise warning #202

Closed RichOnPeers closed 5 years ago

RichOnPeers commented 5 years ago

When mapping over an array of object of players while using API.getPlayerStats an error is returned. Substituting below function to use API.getPlayer makes it run.

(node:21274) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'includes' of undefined at Object.<anonymous> (/.../node_modules/hltv/lib/endpoints/getPlayerStats.js:61:38)

const fetchPlayers = async teams => { const players = getPlayers(teams); / [ { name: "AdreN", id: 334 }, { name: "SANJI", id: 11716 }, { name: "buster", id: 11942 }, { name: "qikert", id: 13239 }, { name: "Jame", id: 13776 } ] /

return await Promise.all( players.map(async item => { const player = await HLTV.getPlayerStats({ id: item.id, startDate: getDateThreeMonthsAgo(), endDate: getTodaysDate() }).then(data => cleanPlayer(data));

  return await player;
})

); };

gigobyte commented 5 years ago

I can't reproduce this issue, all of the IDs you provided work when I call getPlayerStats with them:

HLTV.getPlayerStats({ id: 334 }).then(res => console.log(res))
HLTV.getPlayerStats({ id: 11716 }).then(res => console.log(res))
HLTV.getPlayerStats({ id: 11942 }).then(res => console.log(res))
HLTV.getPlayerStats({ id: 13239 }).then(res => console.log(res))
HLTV.getPlayerStats({ id: 13776 }).then(res => console.log(res))

Prints all successfully.