Vonage / vonage-node-sdk

Vonage API client for Node.js. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
Apache License 2.0
382 stars 181 forks source link

sending process sends null error and result to callback and hung #252

Closed emclab closed 5 years ago

emclab commented 5 years ago

There is nexmo 2.4.1 and nodejs 10.15 in my backend server, sending SMS verification after a user signup. The nexmo SMS has been working fine for sometime but today no SMS verification was received and the nodejs server hung in callback. Here is the code:

sendVcode1:async function(vcode, cell, cell_country_code, device_id, user_id = '') {

switch(process.env.sms) {
    case "nexmo" :
        const nexmo = new Nexmo({
            apiKey: process.env.nexmoApiKey,
            apiSecret: process.env.nexmoApiSecret
        }, { debug: true });        

        nexmo.message.sendSms(process.env.nexmo_sender_number, cell_country_code + cell, vcode, {type: 'unicode'}, async (err, result) => {
            console.log("vcode in nexmo : ", vcode);
            if(err){
                console.error("Vcode failed to send : ", err.message);
                return 'failed to send';  
            }else{
                console.dir("nexmo result : ", result);
                console.log("next step after nexmo result");
                if (user_id) {
                    try {
                        let vr = new VerifLog({
                            vcode: vcode,
                            cell: cell,
                            cell_country_code: cell_country_code,
                            redeemed: false,
                            device_id: device_id,
                            user_id: user_id,
                        });
                        await vr.save();
                        return 'success';
                    } catch (err) {
                        console.log("failed to save verif record : ", err.message);
                        return 'failed to save';
                    };
                };

                return 'success';

            }              
        });

};

},

If there is an error in sending, then if (err) will catch it. Here is the console output on Nodejs server:

info: sending message from 1xxxxxx8344 to 1xxxxx6414 with message 15224 info: Request: { host: 'rest.nexmo.com', port: 443, path: '/sms/json?type=unicode&from=1xxxxxx8344&to=1xxxxxx6414&text=15224&api_key=mykey&api_secret=mysecret', method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json', 'User-Agent': 'nexmo-node/2.4.1 node/10.15.3' } } Body: undefined info: response ended: 200 vcode in nexmo : 15224 'nexmo result : ' next step after nexmo result

The callback hung and did not return even though the status of 200. what caused such behavior and how to fix?

AlexLakatos commented 5 years ago

There hasn't been a new API or Node library release. There was an incident on the 24th with SMS delivery to US & Canada, and that caused message delays and failures. You can read more about it on https://www.nexmostatus.com/.

Did the issue with the callback resolve itself in the meantime?

emclab commented 5 years ago

It was about the time when I was trying to send out SMS message. The code was working and there is no change on the code either. There was nothing returned (both err and result) and the callback did not know how to proceed. Maybe a snippet of code handling NULL return should be added to my callback.

AlexLakatos commented 5 years ago

I think that would be best. And maybe set up delivery receipts, so you can see what happens to the message if it got delivered.

https://developer.nexmo.com/messaging/sms/code-snippets/delivery-receipts/node