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 <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2022-01-17 08:56:43 +01:00
parent 4500caf882
commit 451dedef15
2 changed files with 9 additions and 3 deletions

View file

@ -321,7 +321,7 @@ describe('NotesService', () => {
it('id is forbidden', async () => {
await expect(
service.getNoteByIdOrAlias(forbiddenNoteId),
).rejects.toThrow(ForbiddenIdError);
).rejects.toThrow(NotInDBError);
});
});
});

View file

@ -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<Note> {
@ -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