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

message.sendSms - TypeError: Cannot read property 'status' of undefined #188

Closed
GoEagles999 opened this issue May 27, 2018 · 2 comments
Closed
Assignees

Comments

@GoEagles999
Copy link

GoEagles999 commented May 27, 2018

I am trying to send an SMS message like this:

const from = 'num'
const to = 'num'
const text = 'A text message sent using the Nexmo SMS API'
nexmo.message.sendSms(from, to, text, (error, response) => {
  if(error) {
    throw error;
  } else if(response.messages[0].status != '0') {
    console.error(response);
    throw 'Nexmo returned back a non-zero status';
  } else {
    console.log(response);
  }
});
{ 'message-count': '1',
  messages:
   [ { to: 'num',
       'message-id': '0C000000B7BAC3CE',
       status: '0',
       'remaining-balance': '11.90490000',
       'message-price': '0.03330000',
       network: '23420' } ] }
/srv/node_modules/nexmo/lib/index.js:142
      if (!err && apiResponse.status && apiResponse.messages[0].status > 0) {
                              ^
TypeError: Cannot read property 'status' of undefined

As you can see the message successfully sends (verified on my phone) however this error is thrown from the library immediately after. Why is this happening?

@GoEagles999 GoEagles999 changed the title Node library - message.sendSms - TypeError: Cannot read property 'status' of undefined message.sendSms - TypeError: Cannot read property 'status' of undefined May 27, 2018
@sebastien-cleany
Copy link

Hello,
I got the same issue. It occurs only with node >= 1.2.0.
Thus I supposed, it's related to nodejs/node#20075

I would suggest the following PR in HttpClient.js but I'm not sure

       response.on("close", e => {
+        if (!e) {
+          return;
+        }
         this.logger.error(
           "problem with API request detailed stacktrace below "
         );

I simple workaround is to downgrade Node version to 10.1.0 or below.
I hope this will help you

@AlexLakatos
Copy link
Contributor

Thanks @sebastien-cleany , the proposed fix for this is in issue #191 , will be released in version 2.3.1

@AlexLakatos AlexLakatos self-assigned this Jun 18, 2018
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

3 participants