Vote count:
0
var bcrypt = require('bcrypt-nodejs');
var request = require('request');
var rest_api = require('../../config/rest_api')
var target="sivatest";
function chatMessages(user_name,target){
this.local = {
user_name: user_name,
target : target
};
}
chatMessages.sendChatMessage = function(user_name,target,content){
request.post({url:rest_api.message + user_name +'/'+target, body: {content:content}, json:true},function(err,res) {
console.log("coming back after save chatMessages");
if (err || res.statusCode !== 200){
console.log("return unsuccessfully!");
console.log(res.statusCode);
}
else{console.log("return successfully");}
return;
});
};
chatMessages.getChatMessage = function(user_name,target,callback){
request(rest_api.messages+'/'+user_name+'/'+target,{json:true},function(err,res,body){
console.log("test get");
console.log(res);
console.log(res.statusCode);
if (err){
callback(err,res);
return;
}
if (res.statusCode === 200) {
//window.alert("success");
callback(null,body);
return;
}
if (res.statusCode !== 200) {
//window.alert("null");
callback(null, null);
return;
}
});
};
module.exports = chatMessages;
In the above code, I am able to get the message from my back end server and it shows the status code as 200 and the messages are retrieved correctly. However I get this error in the callback function where the status code reads 200:
TypeError: undefined is not a function
at Request._callback (/Users/ranjani/fse-F14-SA3-SSNoC-Node-UI/app/models/chatRest.js:38:17)
at Request.self.callback (/Users/ranjani/fse-F14-SA3-SSNoC-Node-UI/node_modules/request/request.js:121:22)
at Request.emit (events.js:98:17)
at Request.<anonymous> (/Users/ranjani/fse-F14-SA3-SSNoC-Node-UI/node_modules/request/request.js:985:14)
at Request.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/Users/ranjani/fse-F14-SA3-SSNoC-Node-UI/node_modules/request/request.js:936:12)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:943:16
at process._tickCallback (node.js:419:13
Can anyone suggest where I could be wrong? Thanks
asked 1 min ago
Callback function error in Nodejs
Aucun commentaire:
Enregistrer un commentaire