Add not found error handling for delete
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user