feat(note): handle unique publicId error

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2022-10-03 16:02:32 +02:00
parent 69561e5c63
commit 8201fb8c32
2 changed files with 9 additions and 1 deletions

View file

@ -88,7 +88,7 @@ export class NotesController {
}
@Post()
@OpenApi(201, 413)
@OpenApi(201, 409, 413)
@Permissions(Permission.CREATE)
async createNote(
@RequestUser() user: User,

View file

@ -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;
}