2016-09-16 73 views
0

我面臨着nodejs elasticsearch庫的問題。如果我刪除console.log(hello),以下代碼正在工作並給出結果;但是,如果我添加這個,那麼就沒有錯誤發生。我期待未定義變量「hello」的錯誤消息。我需要查看錯誤消息以進行調試。可能是什麼原因?Nodejs Elasticsearch錯誤未顯示

var elasticsearch = require('elasticsearch'); 
var esClient = new elasticsearch.Client({ 
    host: 'http://mywebsite.com', 
    // log: 'trace' 
}); 


body = {}; 

esClient.search({ 
      index: 'test', 
      type: 'data', 
      body: body 
     }).then(function (resp) { 

      console.log(hello); 
      console.log(resp);  
}); 

回答

0

您確定代碼到達then函數內嗎?也許搜索是拋出一個錯誤,你沒有catch塊???

嘗試:

esClient.search({...}) 
     .then(function (resp) { 

      console.log(hello); 
      console.log(resp);  
     }) 
     .catch(function(error){ 
      console.log(error);  
     }); 

看到,如果你得到任何錯誤呢?

+0

是的,我錯過了「catch」塊。謝謝 :) –