Browse Source

added error handlers on fail reqests in shepherd cache api

all-modes
pbca26 8 years ago
parent
commit
a2d5962a4b
  1. 24
      routes/cache.js

24
routes/cache.js

@ -464,6 +464,16 @@ cache.one = function(req, res, next) {
writeCache(); writeCache();
} }
if (error) {
outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key].data = { 'error': 'request failed' };
outObj.basilisk[coin][address][key].timestamp = 1471620867 // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
callStack[coin]--;
console.log(coin + ' _stack len ' + callStack[coin]);
checkCallStack();
writeCache();
}
}); });
} else { } else {
console.log(key + ' is fresh, check back in ' + (cacheGlobLifetime - checkTimestamp(outObj.basilisk[coin][address][key].timestamp)) + 's'); console.log(key + ' is fresh, check back in ' + (cacheGlobLifetime - checkTimestamp(outObj.basilisk[coin][address][key].timestamp)) + 's');
@ -530,6 +540,10 @@ cache.one = function(req, res, next) {
}); });
} }
} }
if (error) { // stop further requests on failure, exit
callStack[coin] = 1;
checkCallStack();
}
}); });
} else { } else {
getAddresses(coin); getAddresses(coin);
@ -643,6 +657,16 @@ cache.one = function(req, res, next) {
writeCache(); writeCache();
} }
if (error) {
outObj.basilisk[coin][address][key] = {};
outObj.basilisk[coin][address][key].data = { 'error': 'request failed' };
outObj.basilisk[coin][address][key].timestamp = 1471620867 // add timestamp
outObj.basilisk[coin][address][key].status = 'done';
callStack[coin]--;
console.log(coin + ' _stack len ' + callStack[coin]);
checkCallStack();
writeCache();
}
}); });
} else { } else {
console.log(key + ' is fresh, check back in ' + (cacheGlobLifetime - checkTimestamp(outObj.basilisk[coin][address][key].timestamp)) + 's'); console.log(key + ' is fresh, check back in ' + (cacheGlobLifetime - checkTimestamp(outObj.basilisk[coin][address][key].timestamp)) + 's');

Loading…
Cancel
Save