This "solution" given here has a syntax error since you don't have access to `user` within the second then() callback:
get("http://data.com/user")
.then(user => get("http://data.com/location" + user.id))
.then(location => createEntry(user, location))
.then(response => {
// handle response
}).catch(err => {
// handle failure
});
Instead, back before async/await made things easier this nested pattern was used (notice the difference in parenthesis location): get("http://data.com/user")
.then(user => get("http://data.com/location" + user.id)
.then(location => createEntry(user, location)))
.then(response => {
// handle response
}).catch(err => {
// handle failure
});
Edit for completeness, this is how it is now with async/await: try {
const user = await get("http://data.com/user");
const location = await get("http://data.com/location" + user.id);
const response = await createEntry(user, location);
// handle response
} catch (error) {
// handle failure
}