Улучшена обработка ошибок
This commit is contained in:
@@ -21,40 +21,50 @@ class SearchPage extends BasePage {
|
|||||||
let entry = [];
|
let entry = [];
|
||||||
if (query.type) {
|
if (query.type) {
|
||||||
if (['author', 'series', 'title'].includes(query.type)) {
|
if (['author', 'series', 'title'].includes(query.type)) {
|
||||||
const from = query.type;
|
try {
|
||||||
const page = query.page;
|
const from = query.type;
|
||||||
|
const page = query.page;
|
||||||
|
|
||||||
const limit = 100;
|
const limit = 100;
|
||||||
const offset = (page - 1)*limit;
|
const offset = (page - 1)*limit;
|
||||||
const queryRes = await this.webWorker.search(from, {[from]: query.term, del: 0, offset, limit});
|
const queryRes = await this.webWorker.search(from, {[from]: query.term, del: 0, offset, limit});
|
||||||
|
|
||||||
const found = queryRes.found;
|
const found = queryRes.found;
|
||||||
|
|
||||||
for (let i = 0; i < found.length; i++) {
|
for (let i = 0; i < found.length; i++) {
|
||||||
const row = found[i];
|
const row = found[i];
|
||||||
if (!row.bookCount)
|
if (!row.bookCount)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
entry.push(
|
||||||
|
this.makeEntry({
|
||||||
|
id: row.id,
|
||||||
|
title: `${(from === 'series' ? 'Серия: ': '')}${from === 'author' ? this.bookAuthor(row[from]) : row[from]}`,
|
||||||
|
link: this.navLink({href: `/${from}?${from}==${encodeURIComponent(row[from])}`}),
|
||||||
|
content: {
|
||||||
|
'*ATTRS': {type: 'text'},
|
||||||
|
'*TEXT': `${row.bookCount} книг${utils.wordEnding(row.bookCount, 8)}`,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryRes.totalFound > offset + found.length) {
|
||||||
|
entry.push(
|
||||||
|
this.makeEntry({
|
||||||
|
id: 'next_page',
|
||||||
|
title: '[Следующая страница]',
|
||||||
|
link: this.navLink({href: `/${this.id}?type=${from}&term=${encodeURIComponent(query.term)}&page=${page + 1}`}),
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
entry.push(
|
entry.push(
|
||||||
this.makeEntry({
|
this.makeEntry({
|
||||||
id: row.id,
|
id: 'error',
|
||||||
title: `${(from === 'series' ? 'Серия: ': '')}${from === 'author' ? this.bookAuthor(row[from]) : row[from]}`,
|
title: `Ошибка: ${e.message}`,
|
||||||
link: this.navLink({href: `/${from}?${from}==${encodeURIComponent(row[from])}`}),
|
link: this.navLink({href: `/fake-error-link`}),
|
||||||
content: {
|
})
|
||||||
'*ATTRS': {type: 'text'},
|
|
||||||
'*TEXT': `${row.bookCount} книг${utils.wordEnding(row.bookCount, 8)}`,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queryRes.totalFound > offset + found.length) {
|
|
||||||
entry.push(
|
|
||||||
this.makeEntry({
|
|
||||||
id: 'next_page',
|
|
||||||
title: '[Следующая страница]',
|
|
||||||
link: this.navLink({href: `/${this.id}?type=${from}&term=${encodeURIComponent(query.term)}&page=${page + 1}`}),
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user