Commit dfcd47ea authored by Krit Punpreuk's avatar Krit Punpreuk

add handle error

parent 8842e6ac
......@@ -144,6 +144,8 @@ router.get('/:id/bsstime', async (req, res, next) => {
if (query.debug == 'true') {
debug = true
}else {
debug = false
}
// Pick only one
......@@ -207,6 +209,9 @@ router.get('/:id/bsstime', async (req, res, next) => {
} else {
let range = await searchSeq(bss_full_path, t, l, u, "seek")
from_seq = range[0]
if(!from_seq) {
return respHelper.response400('Error read on storage');
}
limit = (range[range.length - 1] - range[0]) + 1
}
printLog("found: " + from_seq + " limit: " + limit,true)
......@@ -245,7 +250,9 @@ router.get('/:id/bsstime', async (req, res, next) => {
from_seq = found[0]
found = await searchSeq(bss_full_path, t[1], from_seq, u2, "right")
limit = found[0] - from_seq + 1
if(!from_seq) {
return respHelper.response400('Error read on storage');
}
// prevent no limit output
if (limit == 0 || limit < 0) {
limit = 1;
......@@ -417,6 +424,7 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) {
let result = []
let rd = bss.reader();
let rec_count = rd.count();
printLog("total record:"+rec_count,debug);
let last_seq = rec_count - 1
let OATZ = Number(rd.rootData.OATZ)
......@@ -439,7 +447,6 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) {
// Prevent out of bound
if (u >= rec_count) { u = last_seq }
if (l < 1) { l = 1 }
let idx = l
let cont = true;
let resultIdx = 0
......@@ -457,6 +464,7 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) {
printLog("l m u : " + l + ", " + idx + ", " + u,debug);
let id = (new ObjId(obj.header.ID)).toString();
printLog("id:"+id,debug);
let dataout = {};
// dataout.ts = parseInt(id.substring(16, id.length), 16)
dataout.ts = obj.meta._ts
......@@ -490,13 +498,18 @@ async function searchSeq(FNAME, t, lowerbound, upperbound, mode) {
result.push(dataout.seq)
cont = false;
}
printLog("before update l or u",debug);
printLog(l,debug);
printLog(u,debug);
printLog(dataout,debug);
if (dataout.ts < t) {
l = Number(dataout.seq)
} else {
u = Number(dataout.seq) - 1
}
idx = Math.ceil((Number(l) + Number(u)) / 2)
printLog("move to : " + idx,debug);
rd.moveTo(idx);
}
resultIdx++
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment