zoukankan      html  css  js  c++  java
  • Cannot set headers after they are sent to the client

    D:le
    ode_modulesmysqllibprotocolParser.js:80
            throw err; // Rethrow non-MySQL errors
            ^
    
    Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the cli
    ent
        at ServerResponse.setHeader (_http_outgoing.js:470:11)
        at ServerResponse.header (D:le
    ode_modulesexpresslib
    esponse.js:767:
    10)
        at ServerResponse.send (D:le
    ode_modulesexpresslib
    esponse.js:170:12
    )
        at ServerResponse.json (D:le
    ode_modulesexpresslib
    esponse.js:267:15
    )
        at ServerResponse.send (D:le
    ode_modulesexpresslib
    esponse.js:158:21
    )
        at D:le
    outescart.js:23:25
        at D:lemodelscart.js:16:14
        at Query._callback (D:lemodelsdb.js:44:22)
        at Query.Sequence.end (D:le
    ode_modulesmysqllibprotocolsequencesSe
    quence.js:88:24)
        at Query.ErrorPacket (D:le
    ode_modulesmysqllibprotocolsequencesQue
    ry.js:90:8)
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! letao@0.0.0 start: `node ./bin/www`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the letao@0.0.0 start script.
    npm ERR! This is probably not a problem with npm. There is likely additional log
    ging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:UsersadministratorAppDataRoaming
    pm-cache\_logs2018-11-28T11_00_46_4
    81Z-debug.log
    
    D:letao>

    注意其中at Query._callback (D:lemodelsdb.js:44:22)找到modelsdb.js44行

        pool.getConnection(function(err, connection) {
            if (err) {
                // callback(err);
                return callback(err);
            }
            connection.query(sqlStr, params, function(err, rows) {
                if (err) {
                    // callback(err);
                    return callback(err);
                }
                connection.release();
                callback.apply(null, arguments);//报错行44
            });
        });

    在callback(err)前加return上述错误解决了。具体原因详见参考文章。

    参考文章:

    https://stackoverflow.com/questions/7042340/error-cant-set-headers-after-they-are-sent-to-the-client
    https://cnodejs.org/topic/53774ffecbcc396349ca1155
    https://cnodejs.org/topic/5635fed78c67728402553324
    https://stackoverflow.com/questions/27658997/cant-set-headers-after-they-are-sent-on-express

  • 相关阅读:
    ASP.NET WebAPI2 发布之后404 Not Found
    WPF MVVM TreeView 实现 右键选中 右键菜单
    Asp.Net MVC4+EF6 Code First 权限管理系统 源码下载
    C# Winform DataGrid 绑定List<> Or ObservableCollection<> 类型无法自动刷新问题
    VMWare 安装时报错 tools-windows.msi failed报错解决办法
    HashMap 扩容机制
    POI解析Excel封装工具
    poi API
    简单echars说明和使用
    比较运算符compareTo()、equals()、==之间的区别
  • 原文地址:https://www.cnblogs.com/codebook/p/10040501.html
Copyright © 2011-2022 走看看