refactor: omit error mapping in GetNoteInterceptor

Because this mapping will now be done with the ErrorExceptionMapping class, the mapping will be omitted in the interceptor.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2022-01-17 09:08:50 +01:00
parent 4ad7ad368c
commit d0477a5e34

View file

@ -4,17 +4,14 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { import {
BadRequestException,
CallHandler, CallHandler,
ExecutionContext, ExecutionContext,
Injectable, Injectable,
NestInterceptor, NestInterceptor,
NotFoundException,
} from '@nestjs/common'; } from '@nestjs/common';
import { Request } from 'express'; import { Request } from 'express';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { ForbiddenIdError, NotInDBError } from '../../errors/errors';
import { Note } from '../../notes/note.entity'; import { Note } from '../../notes/note.entity';
import { NotesService } from '../../notes/notes.service'; import { NotesService } from '../../notes/notes.service';
import { User } from '../../users/user.entity'; import { User } from '../../users/user.entity';
@ -44,17 +41,5 @@ export async function getNote(
noteService: NotesService, noteService: NotesService,
noteIdOrAlias: string, noteIdOrAlias: string,
): Promise<Note> { ): Promise<Note> {
let note: Note; return await noteService.getNoteByIdOrAlias(noteIdOrAlias);
try {
note = await noteService.getNoteByIdOrAlias(noteIdOrAlias);
} catch (e) {
if (e instanceof NotInDBError) {
throw new NotFoundException(e.message);
}
if (e instanceof ForbiddenIdError) {
throw new BadRequestException(e.message);
}
throw e;
}
return note;
} }