DEV Community

Discussion on: Day 17: I hate programming

Collapse
 
nathanbarrett profile image
Nathan Barrett • Edited

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:

  1. 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
});
}

  1. 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!

Thread Thread
 
mtee profile image
Margaret W.N

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.