javascript - UnhandledPromiseRejectionWarning:ReferenceError:未定义响应
问题描述
function getMovies() {
return fetch('http://localhost:3000/movies').then(
response =>{
if(response.status===200){
return response.json();
}
else if(response.status == 404){
return Promise.reject(new Error('Invalid URL'))
done();
}
}).then(moviesListResponse =>{
moviesList = moviesListResponse;
displaymoviesList(moviesList);
return moviesListResponse;
}).catch(error => {
return response.status(404).json({message: 'an error occur'}, error.message);
done();
});
我收到以下错误:
(node:472) UnhandledPromiseRejectionWarning: ReferenceError: response is not defined
at C:\Visual Studio_JavaScript\javascript-movie-cruiser-assignment\public\js\script.js:20:4
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:472) 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_reject`enter code here`ions_mode). (rejection id: 1)
(node:472) [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.
解决方案
推荐阅读
- angular - Angular - router.navigate 给出的路线不正确
- flutter - SingleChildScrollView 在列内不起作用
- sql-server-2012 - SQL Server - 计算接下来的五个工作日
- python - 如何通过代理连接到带有 Python 请求模块的网站?
- reactjs - 有没有办法覆盖现有的 React 组件方法?
- javascript - 渲染错误:“TypeError:无法读取未定义的属性‘first_name’”
- html - 如何使用电子 ipc 更新文本字段
- visual-c++ - 如何获取 C++ 64 位系统信息 App 中显示的总虚拟内存和可用虚拟内存?
- arrays - 要求在字符串数组中插入数字,并重复该问题,直到用户只输入数字。然后使数组成为整数“atoi()”
- c - make/mingw32-make 命令在 Windows 10 上不起作用