mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
refactor: better error logging in JaxRequest
This commit is contained in:
parent
62e4c91e7f
commit
e0adc777e0
2 changed files with 17 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
const { promisify } = require('util')
|
const { promisify } = require('util')
|
||||||
|
const Logger = use('Logger')
|
||||||
const Redis = use('Redis')
|
const Redis = use('Redis')
|
||||||
|
|
||||||
class JaxRequest {
|
class JaxRequest {
|
||||||
|
|
@ -38,7 +39,14 @@ class JaxRequest {
|
||||||
} catch ({ statusCode, ...rest }) {
|
} catch ({ statusCode, ...rest }) {
|
||||||
this.retries--
|
this.retries--
|
||||||
|
|
||||||
if (statusCode !== 503 && statusCode !== 500) return
|
if (statusCode !== 503 && statusCode !== 500) {
|
||||||
|
// Don't log 404 when summoner isn't playing
|
||||||
|
if (!this.endpoint.includes('spectator')) {
|
||||||
|
Logger.transport('file').error(`JaxRequest Error ${statusCode} : `, rest)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
console.log('====================================')
|
console.log('====================================')
|
||||||
console.log(statusCode)
|
console.log(statusCode)
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,9 @@ class MatchService {
|
||||||
// Update Summoner's MatchList
|
// Update Summoner's MatchList
|
||||||
for (const match of matchList.reverse()) {
|
for (const match of matchList.reverse()) {
|
||||||
if (!summonerDB.matchList.some(m => m.gameId === match.gameId)) {
|
if (!summonerDB.matchList.some(m => m.gameId === match.gameId)) {
|
||||||
Logger.transport('file').info(`Match ${match.gameId} has been added to ${account.name}'s MatchList.`)
|
|
||||||
summonerDB.matchList.unshift(match)
|
summonerDB.matchList.unshift(match)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger.transport('file').info(`Summoner ${account.name} has been updated.`)
|
|
||||||
}
|
}
|
||||||
// First search of the Summoner
|
// First search of the Summoner
|
||||||
else {
|
else {
|
||||||
|
|
@ -83,7 +81,6 @@ class MatchService {
|
||||||
})
|
})
|
||||||
// Create Summoner's MatchList in Database
|
// Create Summoner's MatchList in Database
|
||||||
summonerDB.matchList = matchList
|
summonerDB.matchList = matchList
|
||||||
Logger.transport('file').info(`Summoner ${account.name} has been created.`)
|
|
||||||
}
|
}
|
||||||
console.timeEnd('matchList')
|
console.timeEnd('matchList')
|
||||||
}
|
}
|
||||||
|
|
@ -116,16 +113,22 @@ class MatchService {
|
||||||
const ctx = {
|
const ctx = {
|
||||||
account,
|
account,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to see why matches are sometimes undefined
|
||||||
|
matchesFromApi.filter(m => {
|
||||||
|
if(m === undefined) {
|
||||||
|
Logger.transport('file').info('Match undefined', matchesToGetFromRiot)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Transform raw matches data
|
// Transform raw matches data
|
||||||
await BasicMatchTransformer.transform(matchesFromApi, ctx)
|
await BasicMatchTransformer.transform(matchesFromApi, ctx)
|
||||||
Logger.transport('file').info(matchesFromApi)
|
|
||||||
|
|
||||||
/* Save all matches from Riot Api in db */
|
/* Save all matches from Riot Api in db */
|
||||||
for (const match of matchesFromApi) {
|
for (const match of matchesFromApi) {
|
||||||
await summonerDB.matches().create(match)
|
await summonerDB.matches().create(match)
|
||||||
match.newMatch = true
|
match.newMatch = true
|
||||||
}
|
}
|
||||||
console.log('matches saved in db')
|
|
||||||
matchesDetails = [...matchesDetails, ...matchesFromApi]
|
matchesDetails = [...matchesDetails, ...matchesFromApi]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue