#javascript
#javascript
Вопрос:
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_JavaScriptjavascript-movie-cruiser-assignmentpublicjsscript.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.
Комментарии:
1. Где именно находится строка 20 из script.js …?
2. какая польза от done(), если у вас есть возврат в строке-1? ваш ответ не определен в блоке catch, вам не нужно возвращать
3. В этой строке
return response.status(404).json({message: 'an error occur'}, error.message);
откудаresponse
берется? Он не объявлен сверху4. Строка № 20;: возвращает response.status(404).json ({сообщение: «произошла ошибка»}, error.message);
5. Как вы думаете, что это должно делать?