replace crash with something less threatening

This commit is contained in:
Marco van Dijk 2022-04-21 23:54:25 +02:00
parent 8eb1c0c7d5
commit 6fa45acc54
2 changed files with 67 additions and 71 deletions

View File

@ -1890,7 +1890,7 @@ const parseOrchestrator = async function (reqAddr) {
// Not found
if (!orchestratorObj) {
console.log("Pushing null orchestrator " + reqAddr + " @ " + now);
orchestratorCache.push({id: reqAddr, lastGet: now });
orchestratorCache.push({ id: reqAddr, lastGet: now });
return {};
}
orchestratorObj.lastGet = now;
@ -2512,8 +2512,13 @@ const mutateTestScoresToDB = async function (scoreObj, month, year) {
});
}
const zeroPad = (num, places) => String(num).padStart(places, '0')
const getScoreAtMonthYear = async function (month, year) {
const zeroPad = (num, places) => String(num).padStart(places, '0');
// Exports info on a given Orchestrator
apiRouter.post("/getOrchestratorScores", async (req, res) => {
try {
const { month, year } = req.body;
if (month && year) {
// Since months get counted starting at 0
const now = new Date().getTime();
let wasInCache = false;
// See if it is cached
@ -2539,7 +2544,8 @@ const getScoreAtMonthYear = async function (month, year) {
// Else get it and cache it
const url = "https://leaderboard-serverless.vercel.app/api/aggregated_stats?since=" + startTime + "&until=" + endTime;
console.log("Getting new Orchestrator scores for " + year + "-" + month + " @ " + url);
return https.get(url, (res) => {
https.get(url, (res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
@ -2567,7 +2573,7 @@ const getScoreAtMonthYear = async function (month, year) {
}
// Also update monthly stats
mutateTestScoresToDB(scoreObj, month, year);
return scoreObj;
res.send(scoreObj);
} catch (error) {
console.error(error.message);
};
@ -2575,20 +2581,10 @@ const getScoreAtMonthYear = async function (month, year) {
}).on("error", (error) => {
console.error(error.message);
});
}
// Exports info on a given Orchestrator
apiRouter.post("/getOrchestratorScores", async (req, res) => {
try {
const { month, year } = req.body;
if (month && year) {
// Since months get counted starting at 0
const reqObj = await getScoreAtMonthYear(month, year);
res.send(reqObj);
return;
}
} else {
res.send({});
return;
}
} catch (err) {
console.log(err);
res.status(400).send(err);

View File

@ -325,7 +325,7 @@ const WinnerMonth = (obj) => {
}
}
let thisScore = null;
if (thisScores) {
if (thisScores && thisScores.scores) {
thisScore = thisScores.scores[orch.address];
}
return (