nsrestlet
nsrestlet copied to clipboard
Error Message - nsrestlet.js:531
The module regulary crashes at line 531.
TypeError: Cannot read property 'message' of undefined.
Hey there @WimSuenensDIRACIndustries,
It's kinda hard to diagnose the problem without seeing your code. Can you post the following:
- Your Restlet
- The Node.JS code you are using
- I see you are using nodemon. What configuration do you have it running under?
- What version of NSRestlet are you using?
- Which version of Netsuite are you using (they are pushing an update which changes restlets a bit currently and it might be related)
I know some parts of the code may be private, so just post the parts you think might be relevant.
Thanks.
Hi Michael, I can share you these files. I'm using an node-express server which communicates with NetSuite through your package. This server is providing API's to my frontend which is running Angular. My restlet is just returning json. All my calls are working properly, however from time to time the server crashes with this feedback. 'actual_error' is undefined. So, there is some issue in the callbacks. I'm not sure, but it could be an error which occurs when NetSuite is down or unable to reach. Regards, Wim
Hey Wim, thanks, I'll take a look at those. Also, can you tell me the following:
Are you just using default nodemon from the command line (no arguments added)?
Which version of nsrestlet do you have? (Trying to see if it's an earlier version)
Which version is your Netsuite? (Like 2019.1, 2019.2, etc)
Also, as a temporary fix, try the following:
- Go to nsrestlet inside of your node_modules. Find the nsrestlet.js file.
- Change line 531 to the following:
var error_message = error.message || JSON.stringify(error);
Let me know if that works for you.
I'm going to be heading to work soon, so it may be a while before my next response. I'll try to get back to you as soon as I can. Hope your having a good morning -Michael
I'm using default nodemon, indeed. nsrestlet version 2.0.1 and NetSuite 2019.2.
Thanks. Did the fix I posted above work?
I've updated as requested and will test it like this in the next days. As said, they issue occurs for an unknown reason, so I will see in the coming days if it works out correctly. Thanks for the feedback!
Thanks! And yeah, please let me know.
Also, just a note, that code would have only been thrown if Netsuite threw an error. So just make sure your Error catching is smooth and you should be good.
I'll also try and push an updated version of the module with this fix sometime soon.
Hello Michael, FYI: all is working properly. The errors which causes the module to crash were 'ENOTFOUND' and 'ENETDOWN'. I can handle this in my code now. Thanks. Kind regards, Wim
Hey Wim, Thanks for the update. I'll close this for now, but if it happens again, please leave another comment and I'll re-open it right up.
Hope you have an awesome Friday!
Hi,
Same thing happening to me. It only happens once every hundreds of calls, so I'm pretty sure it's a real exception on connection or NetSuite response. Very hard to replicate.
TypeError: Cannot read property 'error' of undefined
at Request._callback (/home/node/io_hubspot/node_modules/nsrestlet/nsrestlet.js:546:28)
at Request.self.callback (/home/node/io_hubspot/node_modules/request/request.js:185:22)
at Request.emit (events.js:321:20)
at Request.<anonymous> (/home/node/io_hubspot/node_modules/request/request.js:1161:10)
at Request.emit (events.js:321:20)
at IncomingMessage.<anonymous> (/home/node/io_hubspot/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:427:28)
at IncomingMessage.emit (events.js:333:22)
at endReadableNT (_stream_readable.js:1201:12)
As it's not returning an error for line # 529 an body is undefined on line 538. I'm not sure if we have other situations where body is allowed to be undefined, could we:
if (error || body === undefined) {
callback(undefined, undefined, undefined); // can even add an error in here
}
Otherwise perhaps add this check after line # 539
if (actual_body === undefined) {
callback(undefined, undefined, undefined);
}
Otherwise: line # 546
if (actual_body !== undefined && actual_body !== null && actual_body.hasOwnProperty('error') actual_body.error && actual_body.error.code)
But looks overkill...
I haven't checked much into the rest of the code, so I'm not sure which style would suite you best or if any of this fixes looks good to you. I can do a PR with any if you prefer.
Hey @mritzco thanks for catching that error. I'll try and push a corrected version up in the next two weeks that (hopefully) catches that.
Sorry about the late response, and hope your week is going well :)
Hey @MichaelEPope, Can you please upgrade your package after resolving all of the above issues. Thanks and regards.
I am also sporadically hitting this error. Any updates on this?
I hit the same issue sometimes. @MichaelEPope
How about this simple/efficient fix line 546?
if (actual_body?.error && actual_body.error?.code)
I've come up with a workaround that doesn't involve modifying node_modules
. This implementation will simply reject the promise if the above exception is encountered.
function callNSEndpoint(method: string, payload: any): Promise<any> {
return new Promise((resolve, reject) => {
const d = domain.create();
d.on('error', reject);
d.run(async () => {
const link = nsrestlet.createLink(this.accountSettings, urlSettings);
const res = await link[method](JSON.parse(payload));
resolve(res);
});
});
}
Note: this has been taken out of context so it will require a little adaptation.