mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
better error handling for search notes
This commit is contained in:
parent
a79a063d17
commit
20fdeee048
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "trilium",
|
"name": "trilium",
|
||||||
"version": "0.39.5",
|
"version": "0.40.0-beta",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -110,6 +110,10 @@ class Note extends Entity {
|
|||||||
async getJsonContent() {
|
async getJsonContent() {
|
||||||
const content = await this.getContent();
|
const content = await this.getContent();
|
||||||
|
|
||||||
|
if (!content || !content.trim()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return JSON.parse(content);
|
return JSON.parse(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +29,12 @@ async function searchFromNote(req) {
|
|||||||
return [404, `Note ${req.params.noteId} has not been found.`];
|
return [404, `Note ${req.params.noteId} has not been found.`];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (note.isDeleted) {
|
||||||
|
return [400, `Note ${req.params.noteId} is deleted.`];
|
||||||
|
}
|
||||||
|
|
||||||
if (note.type !== 'search') {
|
if (note.type !== 'search') {
|
||||||
return [400, '`Note ${req.params.noteId} is not search note.`']
|
return [400, `Note ${req.params.noteId} is not search note.`]
|
||||||
}
|
}
|
||||||
|
|
||||||
const json = await note.getJsonContent();
|
const json = await note.getJsonContent();
|
||||||
@ -41,18 +45,28 @@ async function searchFromNote(req) {
|
|||||||
|
|
||||||
let noteIds;
|
let noteIds;
|
||||||
|
|
||||||
if (json.searchString.startsWith('=')) {
|
try {
|
||||||
const relationName = json.searchString.substr(1).trim();
|
if (json.searchString.startsWith('=')) {
|
||||||
|
const relationName = json.searchString.substr(1).trim();
|
||||||
|
|
||||||
noteIds = await searchFromRelation(note, relationName);
|
noteIds = await searchFromRelation(note, relationName);
|
||||||
|
} else {
|
||||||
|
noteIds = await searchService.searchForNoteIds(json.searchString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
catch (e) {
|
||||||
noteIds = await searchService.searchForNoteIds(json.searchString);
|
log.error(`Search failed for note ${note.noteId}: ` + e.message + ": " + e.stack);
|
||||||
|
|
||||||
|
throw new Error("Search failed, see logs for details.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// we won't return search note's own noteId
|
// we won't return search note's own noteId
|
||||||
noteIds = noteIds.filter(noteId => noteId !== note.noteId);
|
noteIds = noteIds.filter(noteId => noteId !== note.noteId);
|
||||||
|
|
||||||
|
if (noteIds.length > 200) {
|
||||||
|
noteIds = noteIds.slice(0, 200);
|
||||||
|
}
|
||||||
|
|
||||||
return noteIds.map(noteCacheService.getNotePath).filter(res => !!res);
|
return noteIds.map(noteCacheService.getNotePath).filter(res => !!res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user