【问题标题】:Nodejs Elasticsearch errors are not showingNodejs Elasticsearch 错误未显示
【发布时间】:2017-01-24 11:40:03
【问题描述】:

我遇到了 nodejs elasticsearch 库的问题。如果我删除 console.log(hello);,下面的代码正在工作并给出结果但是如果我添加它,那么就不会出现错误。我期待未定义变量“hello”的错误消息。我需要查看错误消息以进行调试。可能是什么原因?

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);    
});

【问题讨论】:

    标签: node.js elasticsearch


    【解决方案1】:

    您确定代码到达then 函数内部吗?也许搜索会抛出错误,而您没有 catch 块???

    试试:

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

    然后看看你有没有报错?

    【讨论】:

    • 是的,我错过了“catch”块。谢谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-10
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 2016-03-03
    • 2012-08-02
    相关资源
    最近更新 更多