We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async saveNew() { const { ctx } = this; try { const rule = { merchant: "object", }; ctx.validate(rule); const uuid = await ctx.service.user.merchant.saveNew(ctx.request.body); this.success(uuid); } catch (err) { const { fields = {}, name } = err; if (name === "SequelizeUniqueConstraintError") { this.fail(ctx.UNIQUE_CODE, 账号:${fields.userName} 的商家已存在); } else { throw new Error(err); } } }
${fields.userName} 的商家已存在
在这段代码中如果抓取err且确实抓取到Unique的错误,确实会报(账号:undefined 的商家已存在)的错误. 可是在后续更换一个账号名去再次注册,且保证账号名是唯一的前提,依旧会报(账号:undefined 的商家已存在)的错误. if (name === "SequelizeUniqueConstraintError") {} 应该是不能用这种方式去捕获错误吧?
if (name === "SequelizeUniqueConstraintError") {}
The text was updated successfully, but these errors were encountered:
还有可能bug是不是出在model.create()失败时 的结果处理中遗漏了reject和catch部分
Sorry, something went wrong.
而导致的数据库阻塞原因?
你好,这个项目基本是我学习的过程,后端代码有的地方写的不成熟或者错误,这里的确不该这么判断,应该有其他更精确的判断
我也是刚在学 前辈有比较成熟基于egg,mysql的商城项目吗? 最好像这份一样带有单页面vue cms系统的
No branches or pull requests
async saveNew() {
const { ctx } = this;
try {
const rule = {
merchant: "object",
};
ctx.validate(rule);
const uuid = await ctx.service.user.merchant.saveNew(ctx.request.body);
this.success(uuid);
} catch (err) {
const { fields = {}, name } = err;
if (name === "SequelizeUniqueConstraintError") {
this.fail(ctx.UNIQUE_CODE, 账号:
${fields.userName} 的商家已存在
);} else {
throw new Error(err);
}
}
}
在这段代码中如果抓取err且确实抓取到Unique的错误,确实会报(账号:undefined 的商家已存在)的错误.
可是在后续更换一个账号名去再次注册,且保证账号名是唯一的前提,依旧会报(账号:undefined 的商家已存在)的错误.
if (name === "SequelizeUniqueConstraintError") {}
应该是不能用这种方式去捕获错误吧?The text was updated successfully, but these errors were encountered: