Closed kvext closed 2 years ago
Hi,
Your client's StartTransaction handler is throwing an error. This, in turn, is causing your server to crash because you haven't handled the error there.
I suggest 2 changes for you:
1) In the client script, change const transactionId = 0;
to let transactionId = 0;
. This will fix your error.
2) In your server's 'client' event listener, you should probably add some error handling to prevent crashes. For example, wrapping the call in a try/catch block like so:
try {
let resTrans = await client.call("StartTransaction", {
connectorId: 0,
idTag: "50-D6-BF-1A-D6-CC",
meterStart: 20,
timestamp: new Date().toISOString(),
});
console.log("Start Transaction Response: ", resTrans);
} catch (err) {
// this catch block will prevent a crash
console.error(`Error starting transaction:`, err);
}
Finally, you may also benefit from setting the option respondWithDetailedErrors: true
in the constructors of both the client & server. This might help in future trying to pinpoint the cause of tricky errors like these; It will add a stack trace from the other side, showing you where the error originated from. (This should only be used for development purposes though, as it may be risky to expose this much information in a production environment.)
Hi @mikuso ,
Thanks a lot! It's working now.
Hi @mikuso,
Hope you're doing good!
I am trying to call one of method "StartTransaction" from server and want to receive response from client, but I am receiving error as below:
My Server Script as below:
Client Script as below:
Can you please provide me suggestion regarding to required to do changes on above?
Thanks,