refactor: change throw error code if not find

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2022-08-07 14:25:30 +08:00
parent 6defdd6ddd
commit 8f4533bafb
4 changed files with 8 additions and 5 deletions

View File

@@ -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,

View File

@@ -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()
}
}

View File

@@ -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) {

View File

@@ -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 () => {