refactor: remove unnessary exception

This commit is contained in:
Innei
2022-06-17 20:57:39 +08:00
parent ae48efeeee
commit 09cca082fb
6 changed files with 10 additions and 15 deletions

View File

@@ -1,7 +0,0 @@
import { InternalServerErrorException } from '@nestjs/common'
export class MasterLostException extends InternalServerErrorException {
constructor() {
super('系统异常,站点主人信息已丢失')
}
}

View File

@@ -59,7 +59,6 @@ export class AllExceptionsFilter implements ExceptionFilter {
const url = request.raw.url!
if (status === HttpStatus.INTERNAL_SERVER_ERROR) {
// message && Logger.debug(message, undefined, 'Catch')
Logger.error(exception, undefined, 'Catch')
this.eventManager.broadcast(
EventBusEvents.SystemException,

View File

@@ -2,12 +2,13 @@ export enum ErrorCodeEnum {
SlugNotAvailable = 'slug_not_available',
BanInDemo = 'ban_in_demo',
MasterLost = 'master_lost',
}
export const ErrorCode = Object.freeze<Record<ErrorCodeEnum, [string, number]>>(
{
[ErrorCodeEnum.SlugNotAvailable]: ['slug 不可用', 400],
[ErrorCodeEnum.BanInDemo]: ['Demo 模式下此操作不可用', 400],
[ErrorCodeEnum.MasterLost]: ['站点主人信息已丢失', 500],
},
)

View File

@@ -5,8 +5,9 @@ import { BadRequestException, Injectable, Logger } from '@nestjs/common'
import { DocumentType } from '@typegoose/typegoose'
import { BeAnObject, ReturnModelType } from '@typegoose/typegoose/lib/types'
import { BusinessException } from '~/common/exceptions/business.exception'
import { CannotFindException } from '~/common/exceptions/cant-find.exception'
import { MasterLostException } from '~/common/exceptions/master-lost.exception'
import { ErrorCodeEnum } from '~/constants/error-code.constant'
import { DatabaseService } from '~/processors/database/database.service'
import {
EmailService,
@@ -229,7 +230,7 @@ export class CommentService {
this.userService.model.findOne().then(async (master) => {
if (!master) {
throw new MasterLostException()
throw new BusinessException(ErrorCodeEnum.MasterLost)
}
const refType = model.refType

View File

@@ -178,7 +178,7 @@ export class NoteService {
async deleteById(id: string) {
const doc = await this.noteModel.findById(id)
if (!doc) {
throw new CannotFindException()
return
}
await Promise.all([

View File

@@ -10,8 +10,9 @@ import {
} from '@nestjs/common'
import { ReturnModelType } from '@typegoose/typegoose'
import { MasterLostException } from '~/common/exceptions/master-lost.exception'
import { BusinessException } from '~/common/exceptions/business.exception'
import { RedisKeys } from '~/constants/cache.constant'
import { ErrorCodeEnum } from '~/constants/error-code.constant'
import { CacheService } from '~/processors/cache/cache.service'
import { InjectModel } from '~/transformers/model.transformer'
import { getAvatar, sleep } from '~/utils'
@@ -102,7 +103,7 @@ export class UserService {
.select('+password +apiToken')
if (!currentUser) {
throw new MasterLostException()
throw new BusinessException(ErrorCodeEnum.MasterLost)
}
// 1. 验证新旧密码是否一致
@@ -131,7 +132,7 @@ export class UserService {
async recordFootstep(ip: string): Promise<Record<string, Date | string>> {
const master = await this.userModel.findOne()
if (!master) {
throw new MasterLostException()
throw new BusinessException(ErrorCodeEnum.MasterLost)
}
const PrevFootstep = {
lastLoginTime: master.lastLoginTime || new Date(1586090559569),