记录一下今天出现的问题,苦恼了很久,结果原因是写错了位置。
错误地方,不应该在路由渲染的地方调用中间件里的方法,位置写错了,导致报错promise里没有.catch处理错误。
代码



User.lastLoginTime应该在 ‘ / ’ 后边
报错信息
(node:12708) UnhandledPromiseRejectionWarning: TypeError: next is not a function
at C:\Users\blog\middleware\user.js:11:5
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:12708) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:12708) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
本文记录了一次在使用Node.js开发后台时遇到的错误——'next is not a function'。问题根源在于在路由渲染的位置错误地调用了中间件的方法,导致Promise中未捕获的错误。解决方案是将User.lastLoginTime的调用放置在正确的位置,即'/‘路由之后。

被折叠的 条评论
为什么被折叠?



