Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Message - nsrestlet.js:531 #4

Open
WimSuenensDIRACIndustries opened this issue Oct 7, 2019 · 15 comments
Open

Error Message - nsrestlet.js:531 #4

WimSuenensDIRACIndustries opened this issue Oct 7, 2019 · 15 comments

Comments

@WimSuenensDIRACIndustries

The module regulary crashes at line 531.
TypeError: Cannot read property 'message' of undefined.
Screenshot 2019-10-07 at 13 20 11

@MichaelEPope
Copy link
Owner

MichaelEPope commented Oct 7, 2019

Hey there @WimSuenensDIRACIndustries,

It's kinda hard to diagnose the problem without seeing your code. Can you post the following:

  1. Your Restlet
  2. The Node.JS code you are using
  3. I see you are using nodemon. What configuration do you have it running under?
  4. What version of NSRestlet are you using?
  5. 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.

@WimSuenensDIRACIndustries
Copy link
Author

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

netsuiteRP.js.pdf
requestRP.js.pdf

@MichaelEPope
Copy link
Owner

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)

@MichaelEPope
Copy link
Owner

Also, as a temporary fix, try the following:

  1. Go to nsrestlet inside of your node_modules. Find the nsrestlet.js file.
  2. 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

@WimSuenensDIRACIndustries
Copy link
Author

I'm using default nodemon, indeed.
nsrestlet version 2.0.1 and NetSuite 2019.2.

@MichaelEPope
Copy link
Owner

Thanks. Did the fix I posted above work?

@WimSuenensDIRACIndustries
Copy link
Author

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!

@MichaelEPope
Copy link
Owner

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.

@WimSuenensDIRACIndustries
Copy link
Author

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

@MichaelEPope
Copy link
Owner

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!

@mritzco
Copy link

mritzco commented Mar 25, 2020

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.

@MichaelEPope
Copy link
Owner

MichaelEPope commented Mar 31, 2020

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 :)

@MichaelEPope MichaelEPope reopened this Mar 31, 2020
@muh-awais
Copy link

Hey @MichaelEPope, Can you please upgrade your package after resolving all of the above issues. Thanks and regards.

@babeard
Copy link

babeard commented Jun 18, 2021

I am also sporadically hitting this error. Any updates on this?

@bluedge
Copy link

bluedge commented Aug 13, 2022

I hit the same issue sometimes. @MichaelEPope
How about this simple/efficient fix line 546?
if (actual_body?.error && actual_body.error?.code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants