promise的then 的问题

来源:8-2 nodejs文件操作

sunleee

2019-06-27

图片描述

(node:10912) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'then' of undefined
    at getPostData.then.postdata (E:\nodejs\blog-2\app.js:45:35)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:10912) 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: 1)
(node:10912) [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.

模仿blog1的书写事,在运行时出现这个问题,定位在下面红色款内,提示then这个属性没有定义,研究了很久也没发现问题所在,希望老师有空帮忙看看解答下

图片描述
这个方法在blog文件这样写的、图片描述
还是把getBlogList方法跟exec方法的图片也贴上吧
图片描述
图片描述

写回答

1回答

双越

2019-06-27

你调用 handleBlogRouter 返回的是 undefined ,你要一行一行代码跟踪看下,应该没有走到你截图的 return 语句中。

一行一行看。

0
4
sunleee
回复
双越
老师我找到问题了。浏览器会请求两次,第一次会请求自己填写的url:/api/blog/list,第二次会请求/favicon.ico 这样第二次不会反悔promise对象,这个问题怎么处理呢。看老师视频的时候并没有对/favicon.ico进行处理。。
2019-06-30
共4条回复

Node.js+Express+Koa2+Nest.js 开发服务端

从入门到实战,一站式掌握 Node.js+Express+Koa2

4086 学习 · 2014 问题

查看课程