Always return cached value when thegraph errors

This commit is contained in:
Marco van Dijk 2022-03-21 15:14:38 +01:00
parent e0795f8bf2
commit d6bfdc2551

View File

@ -585,6 +585,7 @@ apiRouter.get("/getTickets", async (req, res) => {
// Gets info on a given Orchestrator
const parseOrchestrator = async function (reqAddr) {
try {
reqAddr = reqAddr.toLowerCase();
const now = new Date().getTime();
// Default assume it's the first time we request this Orchestrator
@ -668,6 +669,19 @@ const parseOrchestrator = async function (reqAddr) {
}
}
return orchestratorObj;
} catch (err) {
if (wasCached) {
console.log("Thegraph is probably acting up. Returning cached value...");
for (var idx = 0; idx < orchestratorCache.length; idx++) {
if (orchestratorCache[idx].id == reqAddr) {
return orchestratorCache[idx];
}
}
} else{
console.log("Thegraph is probably acting up, but there is no cached value. Returning null...");
return {};
}
}
}
// Exports info on a given Orchestrator
@ -678,7 +692,7 @@ apiRouter.get("/getOrchestrator", async (req, res) => {
reqOrch = CONF_DEFAULT_ORCH;
}
const reqObj = await parseOrchestrator(reqOrch);
res.send(JSON.stringify(reqObj));
res.send(reqObj);
} catch (err) {
console.log(err);
res.status(400).send(err);
@ -687,7 +701,7 @@ apiRouter.get("/getOrchestrator", async (req, res) => {
apiRouter.get("/getOrchestrator/:orch", async (req, res) => {
try {
const reqObj = await parseOrchestrator(req.params.orch);
res.send(JSON.stringify(reqObj));
res.send(reqObj);
} catch (err) {
console.log(err);
res.status(400).send(err);
@ -696,7 +710,7 @@ apiRouter.get("/getOrchestrator/:orch", async (req, res) => {
apiRouter.post("/getOrchestrator", async (req, res) => {
try {
const reqObj = await parseOrchestrator(req.body.orchAddr);
res.send(JSON.stringify(reqObj));
res.send(reqObj);
} catch (err) {
console.log(err);
res.status(400).send(err);