Skip to content

Commit

Permalink
新增全局412错误
Browse files Browse the repository at this point in the history
  • Loading branch information
lfb committed Jun 16, 2019
1 parent 3d7db29 commit 8ef852e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/dao/admin.js
Expand Up @@ -13,7 +13,7 @@ class AdminDao {
});

if (hasAdmin) {
throw new global.errs.Forbidden('管理员已存在');
throw new global.errs.Existing('管理员已存在');
}

const admin = new Admin();
Expand Down
2 changes: 1 addition & 1 deletion app/dao/article.js
Expand Up @@ -21,7 +21,7 @@ class ArticleDao {

// 如果存在,抛出存在信息
if (hasArticle) {
throw new global.errs.Forbidden('文章已存在');
throw new global.errs.Existing('文章已存在');
}

// 创建文章
Expand Down
4 changes: 2 additions & 2 deletions app/dao/category.js
Expand Up @@ -9,13 +9,13 @@ class CategoryDao {
// 查询是否存在重复的分类
const hasCategory = await Category.findOne({
where: {
name: v.get('body.name'),
key: v.get('body.key'),
deleted_at: null
}
});

if (hasCategory) {
throw new global.errs.Forbidden('分类已存在');
throw new global.errs.Existing('分类已存在');
}
;

Expand Down
12 changes: 11 additions & 1 deletion core/http-exception.js
Expand Up @@ -43,10 +43,20 @@ class Forbidden extends HttpException {
}
}

class Existing extends HttpException {
constructor(msg, errorCode) {
super()
this.code = 412
this.msg = msg || '已存在'
this.errorCode = errorCode || 10006
}
}

module.exports = {
HttpException,
ParameterException,
AuthFailed,
NotFound,
Forbidden
Forbidden,
Existing
}

0 comments on commit 8ef852e

Please sign in to comment.