Category: Question and Answers
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Can’t find the reason that the then() not working

Issue

I am experiencing an issue with my code, where the "then()" function inside my "test1" function is not working properly when called by a button. The "testQuery" function seems to work successfully, but none of the handler functions (resolve, reject) are being called. I asked for help and was advised to return the promise from the function in order to resolve the issue, which I did and it worked.

Resolution

The issue was that the test1 function was not returning the promise from the testQuery.run function. To fix this, you need to return the promise from the test1 function. This will allow you to chain the .then function and handle the resolve and reject cases. Here's an updated code example:

export default {
test1: function (params) {
return testQuery.run(params)
.then(() => {
console.log('resolve')
})
.catch(() => {
console.log('reject')
})
}
}

Note that we added a return statement before the call to testQuery.run. Also, we chained the .catch function to handle the reject case. Finally, we made sure to return the promise from the test1 function, which will allow us to chain the .then and .catch functions properly.