Skip to content

Commit

Permalink
perf(init): return more error message
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee committed Jul 16, 2022
1 parent 978fbef commit dd9b6e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 5 additions & 7 deletions src/modules/init/init.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,23 @@ export class InitController {
@Get("/")
@ApiOperation({ summary: "获取初始化情况" })
async canInit() {
return {
canInit: await this.init.canInit(),
};
return await this.init.canInit()
}

@Get("/configs/get/default")
@ApiOperation({ summary: "获取默认配置" })
async initDefault() {
const { canInit } = await this.canInit();
if (!canInit)
const { can_init } = await this.canInit();
if (!can_init)
throw new ForbiddenException("无法获取默认配置,请检查控制台日志");
return this.configs.defaultConfig;
}

@Get("/configs/default")
@ApiOperation({ summary: "初始化默认配置" })
async setConfig() {
const { canInit } = await this.canInit();
if (!canInit)
const { can_init } = await this.canInit();
if (!can_init)
throw new BadRequestException("无法完成初始化,请检查控制台日志");
const defaultConfig = this.configs.defaultConfig;
for (const theKey in defaultConfig) {
Expand Down
18 changes: 14 additions & 4 deletions src/modules/init/init.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ export class InitService {
// 没有用户,不应当初始化
if (!user) {
this.logger.warn("用户未注册,无法初始化");
return false;
return {
can_init: false,
mes: "用户未注册,无法初始化",
reason: 0,
};
} else if (configs.length === 0) {
return true;
return {
can_init: true,
mes: "可以初始化",
};
} else if (configs.length) {
this.logger.warn("配置已存在,无法初始化");
return false;
return {
can_init: false,
mes: "配置已存在,无法初始化",
reason: 1,
};
}
throw new BadRequestException("发生未知错误,无法初始化");
return false;
}
}

0 comments on commit dd9b6e8

Please sign in to comment.