in Elastiflix/javascript-client-elastic-manual/src/components/Header.js [11:49]
function addTofavorites(movie, favorites, setfavorites, setIsLoading, setLastRequestSuccessful) {
setIsLoading(true);
// sleep for 1 second
fetch(endpoint + '/api/favorites', {
method: 'POST',
mode: "cors",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(movie)
})
.then(res => res.json())
.then(data => {
console.log(data.favorites)
console.log(movie.id)
console.log(data)
if (data.error != null) {
setLastRequestSuccessful(false);
console.log("failed to update favorites")
const transaction = apm.startTransaction('custom managed', 'custom', { managed: true })
apm.captureError(new Error("failed to update favorites"))
transaction.end()
} else {
setfavorites(data.favorites)
setLastRequestSuccessful(true);
}
setIsLoading(false);
}).catch(error => {
setIsLoading(false);
setLastRequestSuccessful(false);
console.log(error)
const transaction = apm.startTransaction('custom managed', 'custom', { managed: true })
apm.captureError(error)
transaction.end()
}
)
}