From e0adc777e041db23e69baab5ff7b444a9430e016 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Sat, 13 Jun 2020 23:24:08 +0200 Subject: [PATCH] refactor: better error logging in JaxRequest --- server/app/Services/Jax/src/JaxRequest.js | 10 +++++++++- server/app/Services/MatchService.js | 13 ++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/server/app/Services/Jax/src/JaxRequest.js b/server/app/Services/Jax/src/JaxRequest.js index 81fe23d..db66e5c 100644 --- a/server/app/Services/Jax/src/JaxRequest.js +++ b/server/app/Services/Jax/src/JaxRequest.js @@ -1,4 +1,5 @@ const { promisify } = require('util') +const Logger = use('Logger') const Redis = use('Redis') class JaxRequest { @@ -38,7 +39,14 @@ class JaxRequest { } catch ({ statusCode, ...rest }) { 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(statusCode) diff --git a/server/app/Services/MatchService.js b/server/app/Services/MatchService.js index 53c801d..18bf0fc 100644 --- a/server/app/Services/MatchService.js +++ b/server/app/Services/MatchService.js @@ -68,11 +68,9 @@ class MatchService { // Update Summoner's MatchList for (const match of matchList.reverse()) { 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) } } - Logger.transport('file').info(`Summoner ${account.name} has been updated.`) } // First search of the Summoner else { @@ -83,7 +81,6 @@ class MatchService { }) // Create Summoner's MatchList in Database summonerDB.matchList = matchList - Logger.transport('file').info(`Summoner ${account.name} has been created.`) } console.timeEnd('matchList') } @@ -116,16 +113,22 @@ class MatchService { const ctx = { 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 await BasicMatchTransformer.transform(matchesFromApi, ctx) - Logger.transport('file').info(matchesFromApi) /* Save all matches from Riot Api in db */ for (const match of matchesFromApi) { await summonerDB.matches().create(match) match.newMatch = true } - console.log('matches saved in db') matchesDetails = [...matchesDetails, ...matchesFromApi] }