首页 > 解决方案 > 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.

标签: javascript

解决方案


推荐阅读