-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Is there a way to config the 4xx & 5xx statusCode as normal response but not error #1069
Comments
Actually I'm talking about this: https://github.com/visionmedia/superagent/blob/v2.2.0/lib/node/index.js#L594-L601 |
I think this is one of those API decisions that could go either way. Either you write application code like that to treat responses with error status codes as successful responses or you change the superagent API to treat them as success, but then you have to write application code to look at the status code in the application and respond accordingly. For example, detecting a 404 with HTML in the body when you were expecting a 200 with JSON. I personally wish the original superagent API was "any HTTP response is success" semantics, but it's not. This is something that would be such a breaking change I'd hesitate to change it without something as drastic as forking and renaming the project. I believe that has been discussed on github issues in the past so you might get some insight searching through closed issues for discussion. I know of at least
I would hesitate to make the core API configurable in this way, but I do understand your frustration. |
So since request-promise add configuration to this, how about superagent 🎉 |
Well, if we do it, I'd rather do it with a different API like adding a On Fri, Sep 16, 2016 at 8:37 AM Tao notifications@github.com wrote:
|
I think we could make the logic configurable by allowing user to supply a callback to judge whether the response is OK. https://github.com/visionmedia/superagent/blob/v2.2.0/lib/node/index.js#L590 request.get().ok(res => res.status < 500).then(…) |
ping |
idea: global staticPropertyadd a static property
|
idea: per req configadd a property or method to the request
.get('https://www.google.com.hk')
.config({ detectStatusCode: false }) // <- turn off detectStatusCode here
.end((err, res) => {
// ... blabla
}); I'm 👍 on this too |
but add support short version like |
ping |
Very much works for me. I think if you want all to pass, |
I'm trying to use this function for to test an invalid post request. The function goes like this: I am expecting this to cause validation errors. Any advice on how to use this |
This feature is in superagent. Are you using supertest perhaps? |
I'm pretty sure I'm using superagent, because I'm using chai out of the box. |
Then |
I believe the chai-http plugin is in use here. That has superagent 3.7 which should have |
(chai-http maintainer here) We've yet to add support for this feature in a released version of chai-http. We'll be making a release soon. Thanks for everyone's input here. |
@keithamus Any update? What should we be doing until |
@svicalifornia we should take this off of the superagent tracker. Please track chaijs/chai-http#202 for updates. |
* chai-http currently does not support to properly use 'expect' to specify the bevahiour of calls returning 4XX or 5XX status codes * chaijs/chai-http#75 (comment) * ladjs/superagent#1069 (comment)
As the title presents.
I'm tired of writing code like this
I have to test
!err.original && err.response
exists, and treat it as success response, I'm tired of writing this.So I'm asking is there a way to config that and if not can this issue be a feature request?
The text was updated successfully, but these errors were encountered: