1
節點服務器正在發佈到第三方網站並獲取響應。
如果響應中包含類似Password didn't match.
的內容,服務器會向UI發送錯誤信息,如400: Bad password.
。其他服務器將分析響應並從中發送部分數據。
我無法將errorMessage
發送回UI。如何從anaylzeData方法返回一個錯誤對象並將它發回客戶端?
代碼:節點:設置錯誤消息並將其發送回UI
app.post('/login', [express.urlencoded(), express.json()], function(req, res) {
request.post({
url: 'http://teeSpring.com/login/submitLogin',
form: {
email: req.body.email,
password: req.body.password
}
}, function(error, response, body) {
if (error) {
console.log('Error is: '+JSON.stringify(error));
res.send(400, "There is some problem here.");
} else if(body){
console.log('Body is :')//+JSON.stringify(body));
var serverResp = analyzeData(body);
console.log('Server Response is :'+serverResp);
res.send(serverResp);
}
});
});
analyzeData = function(responseData) {
var respModel=[];
var errorMessage;
$ = cheerio.load(responseData);
$(".errors > p").each(function(i, element) {
console.log($(this).text().indexOf("The password you entered is incorrect"));
if ($(this).text().indexOf("The password you entered is incorrect") >= 0) {
console.log('finds the error')
var error = new Error("Password did not match");
error.code = 400;
errorMessage = error;
return false;
};
});
和問題是什麼? – mihai