Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-10-2019 08:54 AM
I've deployed below code to Cloud Functions to access a graph database(Neo4j Trial on GCP
)
import * as functions from 'firebase-functions';
import * as neo4j from 'neo4j-driver'
export const helloWorld = functions.https.onRequest((request, response) => {
const driver = neo4j.v1.driver("bolt://myaddress", neo4j.v1.auth.basic("username", "password"))
const session = driver.session()
session.run('CREATE (a:Person) SET a.name ={name} RETURN a', {name: 'Vinay'})
.then(result => {
console.log(result);
response.send(result)
session.close();
})
.catch(error => {
session.close();
console.log(error);
response.status(500).send(error)
});
driver.close()
});
when i call the url to access the function it gives the below error as Result
{"code":"ServiceUnavailable","name":"Neo4jError"}
this is the error shown on console when i run it locally
Neo4jError: Client network socket disconnected before secure TLS connection was established
>
> at captureStacktrace (c:\NodeFirebase\functions\node_modules\neo4j-driver\lib\v1\result.js:199:15)
> at new Result (c:\NodeFirebase\functions\node_modules\neo4j-driver\lib\v1\result.js:65:19)
> at Session._run (c:\NodeFirebase\functions\node_modules\neo4j-driver\lib\v1\session.js:152:14)
> at Session.run (c:\NodeFirebase\functions\node_modules\neo4j-driver\lib\v1\session.js:130:19)
> at exports.helloWorld.functions.https.onRequest (c:\NodeFirebase\functions\lib\index.js:11:13)
> at Run (C:\Users\vinay\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:591:20)
> at C:\Users\vinay\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:565:19
> at Generator.next (<anonymous>)
> at C:\Users\vinay\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:7:71
> at new Promise (<anonymous>) code: 'ServiceUnavailable', name: 'Neo4jError' }
What does it mean, how to solve this ?
Solved! Go to Solution.
09-10-2019 12:10 PM
Not yet sure -- but I see a clear problem with your code. The line:
session.run
Doesn't return the promise. This means that it seems your catch block can never occur, because the promise above returns null. It also means that driver.close() probably runs before the session has a chance to do anything.
Always return promises from functions in js. 😉
09-10-2019 12:10 PM
Not yet sure -- but I see a clear problem with your code. The line:
session.run
Doesn't return the promise. This means that it seems your catch block can never occur, because the promise above returns null. It also means that driver.close() probably runs before the session has a chance to do anything.
Always return promises from functions in js. 😉
09-10-2019 12:40 PM
ur right bro, driver.close() runs before the code does anything lol ,just moved driver.close() into catch block and the code works fine, i will put the code in functions from now i need to concentrate haha , Thank you
//for now
session.run('CREATE (a:Person) SET a.name ={name} RETURN a', {name: 'Vinay'})
.then(result => {
session.close();
const singleRecord = result.records[0];
const node = singleRecord.get(0);
// console.log(node.properties.name);
// on application exit:
driver.close();
response.send(node.properties.name)
})
.catch(error => {
session.close();
console.log(error);
response.status(500).send(error)
driver.close()
});
09-10-2019 01:27 PM
Not a problem. Forgetting to return a promise from a JS function is a classic, most people programming threaded promises have done this hundreds of times.....
All the sessions of the conference are now available online