Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status code is ignored when response payload is empty #1170

Closed
StarpTech opened this issue Jul 17, 2018 · 8 comments
Closed

Status code is ignored when response payload is empty #1170

StarpTech opened this issue Jul 17, 2018 · 8 comments
Labels
support General questions or support.

Comments

@StarpTech
Copy link
Contributor

This will return the statusCode 200 but I expect 401. This can be fixed when I pass an empty response body like [401, '']. It this the desired bahviour?

    const verifyPublishedContentMock = Nock(callbackUrl)
      .post('/')
      .query(true)
      .reply(function(uri, requestBody) {
        return [401]
      })
@RichardLitt RichardLitt added pending investigation support General questions or support. labels Jul 17, 2018
@gr2m
Copy link
Member

gr2m commented Jul 23, 2018

Could you please create a runkit notebook such as https://runkit.com/gr2m/node-nock-nock-768 to reproduce the problem?

@StarpTech
Copy link
Contributor Author

@gr2m https://repl.it/@StarpTech/TestCase-1170 if you add a string to the array [401, ''] it will return 401 correctly.

@RichardLitt
Copy link
Member

That looks like the desired behaviour to me. It may just be that you need to send a body, or it will default to 200. Is this an inconvenience?

This is set in lib/interceptor.js:

Interceptor.prototype.reply = function reply(statusCode, body, rawHeaders) {
    if (arguments.length <= 2 && _.isFunction(statusCode)) {
        body = statusCode;
        statusCode = 200;
    }
    ...

@StarpTech
Copy link
Contributor Author

That looks like the desired behaviour to me. It may just be that you need to send a body, or it will default to 200. Is this an inconvenience?

Of course! When I send 401 I expect 401.

@RichardLitt
Copy link
Member

Ok. Someone needs to take a look at the interceptor logic, then. I am at a loss as to how to do this easily.

For now, pass in an empty body in a string.

@StarpTech
Copy link
Contributor Author

@RichardLitt I provide a fix #1203

gr2m pushed a commit that referenced this issue Sep 9, 2018
@gr2m gr2m closed this as completed in #1203 Sep 9, 2018
@nockbot
Copy link
Collaborator

nockbot commented Sep 14, 2018

🎉 This issue has been resolved in version 10.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@lock
Copy link

lock bot commented Sep 28, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support General questions or support.
Projects
None yet
Development

No branches or pull requests

4 participants