log: fix potential log decode error

This commit is contained in:
haishanh 2018-10-23 13:26:37 +08:00
parent 5aa51ae925
commit 61cde9957b
2 changed files with 10 additions and 9 deletions

View file

@ -1,10 +1,10 @@
const textDecoder = new TextDecoder('utf-8');
import {
getAPIConfig,
genCommonHeaders,
getAPIBaseURL
} from 'm/request-helper';
const endpoint = '/logs';
const textDecoder = new TextDecoder('utf-8', { stream: true });
function getURLAndInit() {
const c = getAPIConfig();
@ -44,13 +44,14 @@ function pump(reader) {
return;
}
const t = textDecoder.decode(value);
let o;
const arrRawJSON = t.trim().split('\n');
arrRawJSON.forEach(s => {
try {
o = JSON.parse(t);
store.appendData(JSON.parse(s));
} catch (err) {
console.log(err);
console.log('JSON.parse error', JSON.parse(s));
}
store.appendData(o);
});
return pump(reader);
});
}

View file

@ -1,10 +1,10 @@
const textDecoder = new TextDecoder('utf-8');
import {
getAPIConfig,
genCommonHeaders,
getAPIBaseURL
} from 'm/request-helper';
const endpoint = '/traffic';
const textDecoder = new TextDecoder('utf-8', { stream: true });
function getURLAndInit() {
const c = getAPIConfig();