Add not found error handling for delete

This commit is contained in:
2023-05-28 17:06:19 +09:00
parent 2838beae12
commit 9b51bfda0b
5 changed files with 22 additions and 7 deletions

View File

@@ -46,7 +46,11 @@ export class AlbumController {
@Delete(':id')
async remove(@Param('id', ParseIntPipe) id: number) {
return await this.albumService.deleteAlbum({ id });
try {
return await this.albumService.deleteAlbum({ id });
} catch {
throw new NotFoundException('Invalid ID');
}
}
@Get()

View File

@@ -42,7 +42,11 @@ export class ArtistController {
@Delete(':id')
async remove(@Param('id', ParseIntPipe) id: number) {
return await this.service.delete({ id });
try {
return await this.service.delete({ id });
} catch {
throw new NotFoundException('Invalid ID');
}
}
@Get(':id/illustration')

View File

@@ -41,7 +41,11 @@ export class GenreController {
@Delete(':id')
async remove(@Param('id', ParseIntPipe) id: number) {
return await this.service.delete({ id });
try {
return await this.service.delete({ id });
} catch {
throw new NotFoundException('Invalid ID');
}
}
@Get(':id/illustration')

View File

@@ -93,9 +93,8 @@ export class LessonController {
async delete(@Param('id', ParseIntPipe) id: number): Promise<Lesson> {
try {
return await this.lessonService.delete(id);
} catch (e) {
console.log(e);
throw new BadRequestException(null, e.toString());
} catch {
throw new NotFoundException();
}
}
}

View File

@@ -106,7 +106,11 @@ export class SongController {
@Delete(':id')
async remove(@Param('id', ParseIntPipe) id: number) {
return await this.songService.deleteSong({ id });
try {
return await this.songService.deleteSong({ id });
} catch {
throw new NotFoundException('Invalid ID');
}
}
@Get()