Giter VIP home page Giter VIP logo

kavenegar-node's People

Contributors

aryasadeghy avatar bgsrb avatar chronicless avatar hosseinrezaei188 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kavenegar-node's Issues

Exception! SyntaxError: Unexpected end of JSON input on send function

Exception! SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at IncomingMessage. (****\Server\node_modules\kavenegar\kavenegar.js:36:27)
at IncomingMessage.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1090:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

Dependency is out of date and causes conflict

Hello there.
While trying to resolve the repo using the

npm i kavenegar

commad, I got the error below:

While resolving: [email protected]
Found: [email protected]
node_modules/axios
  axios@"^1.6.1" from [email protected]
  node_modules/axios-ntlm
    axios-ntlm@"^1.2.0" from [email protected]
    node_modules/soap
      soap@"^1.0.0" from the root project
  axios@"^1.6.7" from the root project

Could not resolve dependency:
peer axios@"^0.27.2" from [email protected]
node_modules/soap
  soap@"^1.0.0" from the root project

Conflicting peer dependency: [email protected]
node_modules/axios
  peer axios@"^0.27.2" from [email protected]
  node_modules/soap
    soap@"^1.0.0" from the root project

JSON.parse error on requests with large bodies

On large amount of data , 'data' event called multiple times and in the end 'end' event will be called.
With your CURRENT code single/couple sms sends fine ,because JSON repsponse comes in ONE piece (one 'data' event call), but on mass sms (e.g. on 150 numbers i catch an error because data is not valid JSON ,cause lib try to parse first piece of data and it is not valid , because data contain multiple pieces )
e.on('data', function(data) { var jsonObject = JSON.parse(data); if (callback) callback( jsonObject.entries, jsonObject.return.status, jsonObject.return.message ); });

I modified it like this and issue solved
var req = http.request(post_options, function(e) { e.setEncoding('utf8'); let result = ''; e.on('data', function(data) { result += data; }); e.on('end',function () { try { var jsonObject = JSON.parse(result); if (callback) callback( jsonObject.entries, jsonObject.return.status, jsonObject.return.message ); } catch (e){ console.log('Exception!',e); if(callback){ callback([],500,e.message) } } }) });

Can you , please , make an update in the lib?
Thanks

using promise structure, will help to use methods in transactions

In a case, needed to store new user data in to postgresql database, only when to be sure the SMS message sent, Obviously, i needed to use Transactions.
so i did paint "VerifyLookup" method to act as a promise.

This is my code:

function promisify(r,t,tpl) {
    return new Promise(function (resolve, reject) {
		kapi.VerifyLookup({
			receptor: r,
			token : t,
			template : tpl
		},
		function(response, status) {
			if (status==200)
				resolve(response) ;
			else
				reject(status) ;
		});
    });
}

and in express router by using "sequelize" as ORM and "bcrypt" as hash man:

router.post('/register',function(req,res,next){
	var num = Math.floor(Math.random() * 9000) + 1000;
		bcrypt.genSalt(saltRounds, function(err, salt) {
			bcrypt.hash(req.body.password, salt, function(err, hash) {
				req.body.password = hash ;
				req.body.verificationCode = num ;
				req.body.RoleId = 1 ;
				models.sequelize.transaction(function (t) {
					return models.User.create(req.body, {transaction: t}).then(function(result){
						// send verification code via sms
						return promisify(result.dataValues.mobilePhone,num,'MyTemplate').then(function(status){
							res.status(200).json('Ok') ;
						}).catch(function(e) {
							throw Error(e) ;
						});
						
					})
				}).catch(function(error){
					res.status(500).json(error) ;
				});
			});
		});

});

So, you can try promise structure in next versions of API.

Regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.