MSG91 / sendotp-node

38 stars 24 forks source link

Getting error while using sendotp method #1

Closed gouravbatra closed 7 years ago

gouravbatra commented 7 years ago

Error:- request is not defined at Function.doRequest (/node_modules/sendotp/index.js:161:9)

Code in index.js:- request(options, function(error, response, data) { // request error if (error) { return callback(error, data, response); }

        // JSON parse error or empty strings
        try {
            // An empty string is a valid response
            if (data === '') {
                data = {};
            }
            else {
                data = JSON.parse(data);
            }
        }
        catch(parseError) {
            return callback(
                new Error('JSON parseError with HTTP Status: ' + response.statusCode + ' ' + response.statusMessage),
                data,
                response
            );
        }

        // response object errors
        // This should return an error object not an array of errors
        if (data.errors !== undefined) {
            return callback(data.errors, data, response);
        }

        // status code errors
        if(response.statusCode < 200 || response.statusCode > 299) {
            return callback(
                new Error('HTTP Error: ' + response.statusCode + ' ' + response.statusMessage),
                data,
                response
            );
        }
        // no errors
        callback(null, data, response);
    });
gouravbatra commented 7 years ago

I think there is a bug that.. in index.js they dint required 'request' module. Add require('../request') in index.js file of sendotp module.

rwalkover commented 7 years ago

Issue resolved, changes are pushed you may take a pull.