Skip to content

Commit

Permalink
fix: error messages on 404 (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustDams authored Feb 12, 2023
1 parent 6b62cbf commit 593683c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
11 changes: 4 additions & 7 deletions functions/faceit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions functions/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 593683c

Please sign in to comment.