Closed sentoro closed 5 years ago
@sentoro there are some demo's that do. (https://github.com/ng-apimock/demo)
The @ng-apimock/core does not have anything to do with angular. It provides middleware. So it might be something else.
Could you tell me:
And when you get the error? Do you perform an action? If so, can you provide the mock.json file?
Hello @mdasberg, we found the source of the problem.
It's related to this commit https://github.com/ng-apimock/core/commit/98335c324b4a138831aeaeb3482ded1b13ec2c8d.
In order to reproduce this issue, you need to use mocked file response with wrong file path (in our case it was the absolute file path instead of relative).
In this case, we sent response headers 2 times:
try {
chunk = fs.readFileSync(path.join(params.mock.path, _response.file));
} catch (e) {
response.writeHead(HttpStatusCode.INTERNAL_SERVER_ERROR, HttpHeaders.CONTENT_TYPE_APPLICATION_JSON);
response.end(JSON.stringify(e, ['message']));
}
setTimeout(() => {
response.writeHead(status, headers);
response.end(chunk);
}, delay);
I think we should skip timeout in this case.
@sentoro @pbazurin Thanks for reporting and finding the root cause. A new release has been created to fix this issue. v1.0.17
Update: it was caused by a scenario name which wasn't in the mock. Thus the scenario "Onbekend" was not defined in the selfServiceCustomerStatus mock:
"selfServiceCustomerStatus": {
"scenario": "Onbekend",
"echo": true,
"delay": 0,
"counter": 0
},
I seem to have the same error at this time :-S
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client at ServerResponse.setHeader (_http_outgoing.js:558:11) at ServerResponse.writeHead (_http_server.js:289:21) at SelectPresetHandler.handle (/home/sander/AthoraNx/node_modules/@ng-apimock/core/src/core/middleware/handlers/api/select-preset.handler.ts:59:22) at /home/sander/AthoraNx/node_modules/@ng-apimock/core/src/core/middleware/middleware.ts:115:25
I suspect it has something to do with the combination of the cypress-plugin and the ngapimock/core versions. "@ng-apimock/core": "^3.0.1", "@ng-apimock/cypress-plugin": "^1.1.0", "@ng-apimock/dev-interface": "^2.0.0",
Does anyone tested it with latest Angular ? It is not working for me anymore. I see:
_http_outgoing.js:491 throw new Error('Can\'t set headers after they are sent.');
server.js: