Добавлена обработка ошибок JSON.parse

This commit is contained in:
Book Pauk
2020-01-12 20:06:50 +07:00
parent 6faa7b2efe
commit 52a32cfdd1

View File

@@ -37,7 +37,11 @@ class Reader {
//быстрее будет last.split //быстрее будет last.split
const res = last.split(splitter).pop(); const res = last.split(splitter).pop();
if (res) { if (res) {
callback(JSON.parse(res)); try {
callback(JSON.parse(res));
} catch (e) {
//
}
} }
} }
}); });
@@ -46,8 +50,14 @@ class Reader {
response = response.data.split(splitter).pop(); response = response.data.split(splitter).pop();
if (response) { if (response) {
response = JSON.parse(response); try {
response = JSON.parse(response);
} catch (e) {
response = false;
}
}
if (response) {
if (response.state == 'finish') {//воркер закончил работу, можно скачивать кешированный на сервере файл if (response.state == 'finish') {//воркер закончил работу, можно скачивать кешированный на сервере файл
callback({step: 4}); callback({step: 4});
const book = await this.loadCachedBook(response.path, callback); const book = await this.loadCachedBook(response.path, callback);