gpt4 book ai didi

node.js - Loopback.io错误: Can't set headers after they are sent.确认用户

转载 作者:太空宇宙 更新时间:2023-11-03 22:15:54 25 4
gpt4 key购买 nike

我正在使用 mocha 和 supertest 来创建功能测试。以下是测试的副本。

it("should verify user POST /api/User/confirm", function (done) {
app.models.Users.findById(userId, function (err, usr) {
json('get', '/api/user/confirm?uid=' + userId + '&token=' + usr.verificationToken)
.expect(204,done);
});
});

但是这个测试返回:

Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:689:11)
at ServerResponse.res.setHeader (/node_modules/loopback-explorer/node_modules/express/node_modules/connect/lib/patch.js:134:22)
at ServerResponse.header (/node_modules/loopback/node_modules/express/lib/response.js:700:10)
at ServerResponse.send (/node_modules/loopback/node_modules/express/lib/response.js:154:12)
at ServerResponse.json (/node_modules/loopback/node_modules/express/lib/response.js:240:15)
at ServerResponse.send (/node_modules/loopback/node_modules/express/lib/response.js:142:21)
at defaultHandler (/node_modules/loopback/node_modules/strong-remoting/lib/rest-adapter.js:379:11)
at restErrorHandler (/node_modules/loopback/node_modules/strong-remoting/lib/rest-adapter.js:348:14)
at Layer.handle_error (/node_modules/loopback/node_modules/express/lib/router/layer.js:58:5)
at trim_prefix (/node_modules/loopback/node_modules/express/lib/router/index.js:300:13)
at /node_modules/loopback/node_modules/express/lib/router/index.js:270:7
at Function.proto.process_params (/node_modules/loopback/node_modules/express/lib/router/index.js:321:12)
at next (/node_modules/loopback/node_modules/express/lib/router/index.js:261:10)
at Layer.handle_error (/node_modules/loopback/node_modules/express/lib/router/layer.js:54:12)
at trim_prefix (/node_modules/loopback/node_modules/express/lib/router/index.js:300:13)
at /node_modules/loopback/node_modules/express/lib/router/index.js:270:7
at Function.proto.process_params (/node_modules/loopback/node_modules/express/lib/router/index.js:321:12)
at Object.next (/node_modules/loopback/node_modules/express/lib/router/index.js:261:10)
at Object. (/node_modules/loopback/node_modules/express/lib/router/index.js:603:15)
at Object. (/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31)
at Object.immediate._onImmediate (timers.js:363:16)
at processImmediate as _immediateCallback

此时我正在使用最新版本的环回。有人能指出我正确的方向吗?

最佳答案

这通常是由于代码中多次使用 res.send() 造成的。我会检查一下是否是这种情况。

关于node.js - Loopback.io错误: Can't set headers after they are sent.确认用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29075995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com