ok, after a quick review one thing did stand out. your async function addNewHabit does not return a promise. also, async functions should always return a promise. you can achieve that in one of two ways:
everything inside the function is wrapped with a Promise:
let myFunction = async function () {
return new Promise((resolve, reject) => {
// do function stuff and resolve(data) or reject(error) when done
});
}
if you are doing additional await stuff inside the async function you can return a fully resolved or rejected promise like so:
let myFunction = async function () {
let data
try {
data = await someOtherAsyncFunction();
} catch (error) {
return Promise.reject(error)
}
return Promise.resolve(data)
}
so in your code I would change "return newHabit" to "return Promise.resolve(newHabit)"
remember, async functions will always return a Promise
if you need any additional help or get stuck again feel free to hit me up. good luck!
ok, after a quick review one thing did stand out. your async function addNewHabit does not return a promise. also, async functions should always return a promise. you can achieve that in one of two ways:
let myFunction = async function () {
return new Promise((resolve, reject) => {
// do function stuff and resolve(data) or reject(error) when done
});
}
let myFunction = async function () {
let data
try {
data = await someOtherAsyncFunction();
} catch (error) {
return Promise.reject(error)
}
return Promise.resolve(data)
}
so in your code I would change "return newHabit" to "return Promise.resolve(newHabit)"
remember, async functions will always return a Promise
if you need any additional help or get stuck again feel free to hit me up. good luck!
I'll make the changes and reach out if i get stuck. Thank you for taking your time to review the code. I'm grateful.