I am using Javascript fetch API to post data to a json server. But I am getting UnhandledPromiseRejection Warning. Below is the code, plese help in finding the issue in the code.
function addFavourite(movieid) {
if (!favMovies.find(x => x.id == movieid)) {
let movie=movies.find((x)=>x.id==movieid);
//console.log(movie);
//addFavourite(movie);
return fetch("http://localhost:3000/favourites", {
method: "POST",
headers:{
"Contenet-Type": "application/json"
},
body: JSON.stringify(movie),
}).then((response) => {
favMovies.push(movie);
return response.json();
}).then((response)=>{
return response;
}).catch((error)=>{
return (error);
});;
} else {
throw new Error('Movie is already added to favourites');
}
}
(node:7358) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: AssertionError: expected { Object (voteCount, id, ...) } to deeply equal [ Array(2) ]: expected { Object (message, showDiff, ...) } to equal null (node:7358) [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.