Reputation: 1558
I am calling a Cloud Function on Android App and the return value is null, it works fine when onRequest is used instead of onCall from browser, but when the function is called from Android App using OnCall it returns null
Code:
export const userExistsOrNot = functions.https.onCall((data, context) => {
const driver = neo4j.v1.driver("uri", neo4j.v1.auth.basic("usr", "pwd"), {connectionTimeout: 30 * 1000})
const session = driver.session()
session.readTransaction(wrte=>{
let r : any
if(context.auth){
r = wrte.run('MATCH (a:Person) WHERE a.userid ={userid} RETURN exists(a.userid)',
{userid: context.auth.uid})
}
return r as neo4j.v1.Result
}
)
.then(result => {
session.close();
driver.close();
if(result.records[0] == null){
return {
"data": {
"text": 0
}
}
} else {
return {
"data": {
"text": 1
}
}
}
})
.catch(error => {
session.close();
console.log(error);
driver.close()
throw new functions.https.HttpsError(error,"some error");
});
});
Upvotes: 0
Views: 44
Reputation: 317352
Your top-level callback function isn't returning a promise that resolves with the value to send to the client after all the asynchronous work is complete. In fact, it isn't returning any promise at all. You will need to write your code such that it returns that promise to the client, I suggest starting out with something much simpler in order to understand how it works.
Upvotes: 1