2014-03-02 1 views
1

노드 서버가 제 3 자 웹 사이트에 게시하고 응답을 다시 받고 있습니다.
응답에 Password didn't match.과 같은 내용이 포함되어 있으면 서버에서 400: Bad password.과 같은 오류가 UI에 전송됩니다. 다른 사람이 응답을 분석하고 데이터의 일부를 보냅니다.
errorMessage을 UI로 되돌릴 수 없습니다. 어떻게 anaylzeData 메서드에서 오류 개체를 반환하고 다시 클라이언트로 보낼 수 있습니까?
코드 : 당신은 analyzeData에 성공 케이스 아무것도 반환하지 않습니다노드 : 오류 메시지 설정 및 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; 
    }; 
    }); 
+0

및 질문은? – mihai

답변

관련 문제