From 451dedef158ec234091208f17c2a4a1d5b0546b4 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Mon, 17 Jan 2022 08:56:43 +0100 Subject: [PATCH] refactor: getNoteByIdOrAlias throws NotInDBError instead of ForbiddenIdError for an id on the forbidden list It's not really necessary to tell the user via get that this id is forbidden, it will not be there and as such NotInDBError is the correct message to the user Signed-off-by: Philip Molares --- src/notes/notes.service.spec.ts | 2 +- src/notes/notes.service.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/notes/notes.service.spec.ts b/src/notes/notes.service.spec.ts index 228e0f9fb..b1819f4d0 100644 --- a/src/notes/notes.service.spec.ts +++ b/src/notes/notes.service.spec.ts @@ -321,7 +321,7 @@ describe('NotesService', () => { it('id is forbidden', async () => { await expect( service.getNoteByIdOrAlias(forbiddenNoteId), - ).rejects.toThrow(ForbiddenIdError); + ).rejects.toThrow(NotInDBError); }); }); }); diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 99c33904b..484c7ce89 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -156,7 +156,6 @@ export class NotesService { * Get a note by either their id or alias. * @param {string} noteIdOrAlias - the notes id or alias * @return {Note} the note - * @throws {ForbiddenIdError} the requested id or alias is forbidden * @throws {NotInDBError} there is no note with this id or alias */ async getNoteByIdOrAlias(noteIdOrAlias: string): Promise { @@ -164,7 +163,14 @@ export class NotesService { `Trying to find note '${noteIdOrAlias}'`, 'getNoteByIdOrAlias', ); - this.checkNoteIdOrAlias(noteIdOrAlias); + try { + this.checkNoteIdOrAlias(noteIdOrAlias); + } catch (e) { + if (e instanceof ForbiddenIdError) { + throw new NotInDBError(e.message); + } + throw e; + } /** * This query gets the note's aliases, owner, groupPermissions (and the groups), userPermissions (and the users) and tags and