警告

(node:8500) UnhandledPromiseRejectionWarning: undefined
(node:8500) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:8500) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with

报错代码

//数据库中是否已经存在同名分类名称
Category.findOne({
name: name
}).then(function (rs) {
if (rs) {
//数据库中已经存在该分类
res.render('admin/error',{
userInfo: req.userInfo,
message: '分类已经存在'
});
return Promise.reject();
} else {
//数据库中不存在该分类,可以保存
return new Category({
name: name
}).save();
}
}).then(function (newCategory) {
res.render('admin/success',{
userInfo: req.userInfo,
message: '分类保存成功',
url: '/admin/category'
});
})

报错原因:因为Promise的reject没有被处理。

如果不管异常内容,直接丢弃异常,可以这样处理:.catch(()=>{});

修改后代码

//数据库中是否已经存在同名分类名称
Category.findOne({
name: name
}).then(function (rs) {
if (rs) {
//数据库中已经存在该分类
res.render('admin/error',{
userInfo: req.userInfo,
message: '分类已经存在'
});
return Promise.reject();
} else {
//数据库中不存在该分类,可以保存
return new Category({
name: name
}).save();
}
}).then(function (newCategory) {
res.render('admin/success',{
userInfo: req.userInfo,
message: '分类保存成功',
url: '/admin/category'
});
}).catch(()=>{});

最新文章

  1. Linux sort 命令
  2. web-inf目录和meta-inf目录
  3. 【javascript】箭头函数
  4. null
  5. The Nine Indispensable Rules for HW/SW Debugging 软硬件调试之9条军规
  6. rabbitmq redis
  7. C语言输出规定长度的整数,不够位数前面补零
  8. Winform 控件使用集锦
  9. css布局小技巧 2016.03.06
  10. Vxworks、QNX、Xenomai、Intime、Sylixos、Ucos等实时操作系统的性能特点
  11. c/c++重定向输入输出
  12. python开发 getpass获取操作系统登陆名
  13. git初试
  14. WIP完工入库及完工退回的几个重要问题
  15. Windows系统pip安装whl包
  16. Python高级笔记(二) -- 深拷贝和浅拷贝
  17. selenium——find_element_by_xx 与 find_element(By.XX,'XXXX')
  18. 1分钟快速制作漂亮的H5本地记事本
  19. 如何去掉C#字符串中的所有空格
  20. 铁板纹理 铁锈Rust

热门文章

  1. java 上传大文件以及文件夹
  2. 【Leetcode】二叉树的层次遍历
  3. 基于数组阻塞队列 ArrayBlockingQueue 的一个队列工具类
  4. centos7 安装 eclipse
  5. springMVC @response 中文乱码解决
  6. &&的运算顺序
  7. zay大爷的神仙题目 D1T2-腐草为萤
  8. 在SOUI3中使用预编译XML
  9. 2018-5 - 凉经 - Mozilla Firefox Ltd - 前端工程师
  10. hibernate 2 多对多映射