From 8f4533bafbc2ccec2ff8de972a91d276c2a27655 Mon Sep 17 00:00:00 2001 From: Innei Date: Sun, 7 Aug 2022 14:25:30 +0800 Subject: [PATCH] refactor: change throw error code if not find Signed-off-by: Innei --- src/modules/category/category.controller.ts | 3 ++- src/modules/comment/comment.controller.ts | 3 ++- src/modules/comment/comment.service.ts | 3 ++- src/modules/page/page.service.ts | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/modules/category/category.controller.ts b/src/modules/category/category.controller.ts index f16054d5..9145dcc5 100644 --- a/src/modules/category/category.controller.ts +++ b/src/modules/category/category.controller.ts @@ -21,6 +21,7 @@ import { Auth } from '~/common/decorator/auth.decorator' import { HTTPDecorators } from '~/common/decorator/http.decorator' import { ApiName } from '~/common/decorator/openapi.decorator' import { CannotFindException } from '~/common/exceptions/cant-find.exception' +import { NoContentCanBeModifiedException } from '~/common/exceptions/no-content-canbe-modified.exception' import { MongoIdDto } from '~/shared/dto/id.dto' import { PostService } from '../post/post.service' @@ -171,7 +172,7 @@ export class CategoryController { const { id } = params const category = await this.categoryService.model.findById(id) if (!category) { - throw new CannotFindException() + throw new NoContentCanBeModifiedException() } const postsInCategory = await this.categoryService.findPostsInCategory( category._id, diff --git a/src/modules/comment/comment.controller.ts b/src/modules/comment/comment.controller.ts index a4bc4b01..50451c45 100644 --- a/src/modules/comment/comment.controller.ts +++ b/src/modules/comment/comment.controller.ts @@ -24,6 +24,7 @@ import { IpLocation, IpRecord } from '~/common/decorator/ip.decorator' import { ApiName } from '~/common/decorator/openapi.decorator' import { IsMaster } from '~/common/decorator/role.decorator' import { CannotFindException } from '~/common/exceptions/cant-find.exception' +import { NoContentCanBeModifiedException } from '~/common/exceptions/no-content-canbe-modified.exception' import { BusinessEvents, EventScope } from '~/constants/business-event.constant' import { ReplyMailType } from '~/processors/helper/helper.email.service' import { EventManagerService } from '~/processors/helper/helper.event.service' @@ -404,7 +405,7 @@ export class CommentController { return } catch { - throw new CannotFindException() + throw new NoContentCanBeModifiedException() } } diff --git a/src/modules/comment/comment.service.ts b/src/modules/comment/comment.service.ts index a0f9c47f..d4ad60eb 100644 --- a/src/modules/comment/comment.service.ts +++ b/src/modules/comment/comment.service.ts @@ -12,6 +12,7 @@ import { BeAnObject, ReturnModelType } from '@typegoose/typegoose/lib/types' import { BusinessException } from '~/common/exceptions/biz.exception' import { CannotFindException } from '~/common/exceptions/cant-find.exception' +import { NoContentCanBeModifiedException } from '~/common/exceptions/no-content-canbe-modified.exception' import { ErrorCodeEnum } from '~/constants/error-code.constant' import { DatabaseService } from '~/processors/database/database.service' import { @@ -162,7 +163,7 @@ export class CommentService { async deleteComments(id: string) { const comment = await this.commentModel.findOneAndDelete({ _id: id }) if (!comment) { - throw new CannotFindException() + throw new NoContentCanBeModifiedException() } const { children, parent } = comment if (children && children.length > 0) { diff --git a/src/modules/page/page.service.ts b/src/modules/page/page.service.ts index 2aa11fde..a1b519cc 100644 --- a/src/modules/page/page.service.ts +++ b/src/modules/page/page.service.ts @@ -4,7 +4,7 @@ import slugify from 'slugify' import { Injectable } from '@nestjs/common' -import { CannotFindException } from '~/common/exceptions/cant-find.exception' +import { NoContentCanBeModifiedException } from '~/common/exceptions/no-content-canbe-modified.exception' import { BusinessEvents, EventScope } from '~/constants/business-event.constant' import { EventManagerService } from '~/processors/helper/helper.event.service' import { ImageService } from '~/processors/helper/helper.image.service' @@ -63,7 +63,7 @@ export class PageService { .lean({ getters: true }) if (!newDoc) { - throw new CannotFindException() + throw new NoContentCanBeModifiedException() } process.nextTick(async () => {