#Function async issue
19 messages · Page 1 of 1 (latest)
export const generateNotes = async (userId, uid, topic, context, error) => {
try {
const study = await notesModel.generateContent(JSON.stringify({ uid, topic_name: topic, topic_context: context }))
const data = study.response.text
if (isResponseValid(data)) await saveInDatabase(userId, data)
else await saveInDatabase(userId, "Error occured! Please try again!")
} catch (err) {
error(`Error generating notes: ${err}`)
}
}
NodeJS
no. i dont get any errors in the console
That's everything?
You're not using appwrite SDK?
Do you have initialized the SDK?
What's saveindatabase doing?
What's the code for that?
@scarlet spear it simply saves the response in separate collection for retrieval (polling)
export const saveInDatabase = async (documentId, data) => {
await databases.createDocument(
process.env.DATABASE_ID,
process.env.GEN_COLLECTION_ID,
documentId,
{ data }
)
}
@scarlet spear also in my main.js i return a json object. is that making it run in sync?
Hmm maybe 🤔
I will check after removing that and let you know