diff --git a/functions/faceit.js b/functions/faceit.js index 7c9a6090..70898b52 100644 --- a/functions/faceit.js +++ b/functions/faceit.js @@ -9,14 +9,11 @@ const headerFaceit = { const fetchData = async (url, error) => axios.get(url, { headers: headerFaceit }) - .then(res => { - if (res.status == 200) return res.data - else { - console.error(res.statusText, res.url) - throw error - } + .then(res => res.data) + .catch(e => { + console.error(e.response.status, e.response.statusText, url) + throw error }) - .then(data => data) module.exports = { fetchData diff --git a/functions/match.js b/functions/match.js index e61fc511..2690e290 100644 --- a/functions/match.js +++ b/functions/match.js @@ -2,14 +2,11 @@ const axios = require('axios') const Faceit = require('./faceit') const getMatchElo = (playerId, limit = 20, page = 0) => axios.get(`https://api.faceit.com/stats/api/v1/stats/time/users/${playerId}/games/csgo?size=${limit}&page=${page}`) - .then(res => { - if (res.status == 200) return res.data - else { - console.error(res.statusText, res.url) - throw 'Couldn\'t get matches' - } + .then(res => res.data) + .catch(e => { + console.error(e.response.status, e.response.statusText, playerId) + throw 'Couldn\'t get matches' }) - .then(data => data) const getMatchStats = matchid => Faceit.fetchData(`https://open.faceit.com/data/v4/matches/${matchid}/stats`, 'Couldn\'t get matches stats')