From 8201fb8c320b73b9e6f2d2ddbd73fb7d8ca83250 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Mon, 3 Oct 2022 16:02:32 +0200 Subject: [PATCH] feat(note): handle unique publicId error Signed-off-by: Philip Molares --- src/api/private/notes/notes.controller.ts | 2 +- src/notes/notes.service.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/api/private/notes/notes.controller.ts b/src/api/private/notes/notes.controller.ts index c4d1ec8ab..a8af15d34 100644 --- a/src/api/private/notes/notes.controller.ts +++ b/src/api/private/notes/notes.controller.ts @@ -88,7 +88,7 @@ export class NotesController { } @Post() - @OpenApi(201, 413) + @OpenApi(201, 409, 413) @Permissions(Permission.CREATE) async createNote( @RequestUser() user: User, diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 60df45400..3e61c397f 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -139,6 +139,14 @@ export class NotesService { throw new AlreadyInDBError( `A note with the alias '${alias}' already exists.`, ); + } else if ((e as Error).message.includes('publicId')) { + this.logger.debug( + `A note with the publicId '${newNote.publicId}' already exists.`, + 'createNote', + ); + throw new AlreadyInDBError( + `A note with the publicId '${newNote.publicId}' already exists.`, + ); } else { throw e; }