Skip to content

Commit

Permalink
do not handle exceptions manually wo intention
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 committed Aug 18, 2024
1 parent d7eb9d9 commit bc6bae0
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions src/popo/noticeLike/noticeLike.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ import { ApiBody, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
import { NoticeLikeDto } from './noticeLike.dto';
import { NoticeLikeService } from './noticeLike.service';
import { QueryFailedError } from 'typeorm';
import { NoticeLike } from './noticeLike.entity';

const Message = {
FAIL_LIKE_DELETION_NEVER_LIKED: 'There is no record of liking the post.',
FAIL_DUPLICATE_ENTRY: 'Duplicate entry detected',
FAIL_INTERNAL_SERVER: 'Internal server error',
};

@ApiTags('Notice Like')
Expand All @@ -33,21 +30,7 @@ export class NoticeLikeController {
@UseGuards(JwtAuthGuard)
@ApiBody({ type: NoticeLikeDto })
async create(@Body() dto: NoticeLikeDto): Promise<NoticeLike> {
try {
return await this.noticeLikeService.save(dto);
} catch (e) {
if (e instanceof QueryFailedError) {
throw new HttpException(
Message.FAIL_DUPLICATE_ENTRY,
HttpStatus.CONFLICT,
);
} else {
throw new HttpException(
Message.FAIL_INTERNAL_SERVER,
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
return await this.noticeLikeService.save(dto);
}

@Get('count')
Expand Down

0 comments on commit bc6bae0

Please sign in to comment.