Nock returning statusCode 200 instead of 404
See original GitHub issueI am trying an example that matches the following code.
nock('https://api.orchestrate.io:443')
.get('/v0/addInSetTest/0')
.reply(404, {"message":"The requested items could not be found.","details":{"items":[{"collection":"addInSetTest","key":"0"}]},"code":"items_not_found"}, { 'content-type': 'application/json',
date: 'Fri, 13 Jun 2014 18:51:05 GMT',
'x-orchestrate-req-id': 'ac8d94f0-f32b-11e3-82c9-12313d2f7cdc',
'content-length': '140',
connection: 'Close' });
In my case, nock is returning status code 200
instead 404
. Any ideas?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top Results From Across the Web
ASP.NET Custom 404 Returning 200 OK Instead of 404 Not ...
A 404 status code will require a Server.Transfer instead of a Request.Redirect, along with the appropriate status code written in the header.
Read more >Solved: Getting error 404 Not Found but expecting 200 when...
Solved: Hi, I have a GET step which uses the this URL " https://inter.comp.se/v1/state/${Properties1#agreement}/tree ". Now when I run this.
Read more >To err or not to err: 404 vs 200 - GSiteCrawler
Even custom error pages must return result-code 404 instead of 200. A search engine thinks that pages with 200 are good URLs and...
Read more >Creating Responses - Requests-Mock - Read the Docs
status_code: The HTTP status response to return. Defaults to 200. reason: The reason text that accompanies the Status (e.g. 'OK' in '200 OK')....
Read more >nock - npm
You can specify the return status code for a path on the first argument of ... nock('http://myapp.iriscouch.com').get('/users/1').reply(404).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lordakshaya as far as I understand,
Code.expect(response.statusCode).to.equal(404);
passes whileCode.expect(response.result.error).to.equal('Not Found');
fails.If this is the case, I think
response.result
only existson('data')
oron('end')
(see: https://nodejs.org/dist/latest-v6.x/docs/api/http.html#http_http_request_options_callback).Could you please verify if this is the case?
@vrinek apologies for the delayed response, here’s the full code:
And here’s the output of the test:
Please re-open the issue.