Is there a way to config the 4xx & 5xx statusCode as normal response but not error
See original GitHub issueAs the title presents.
I’m tired of writing code like this
const getDataAsync = co.wrap(function*(){
let res;
try {
res = yield request.get('some_url')
} catch(err) {
if(!err.original && err.response) {
res = err.response
} else {
throw err;
}
}
});
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?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:19 (13 by maintainers)
Top Results From Across the Web
Is there a way to config the 4xx & 5xx statusCode as normal ...
I have to test !err.original && err.response exists, and treat it as success response, I'm tired of writing this.
Read more >When should an API throw a 4xx status code (error) and when ...
On the W3C site it says: Client Error 4xx The 4xx class of status code is intended for cases in which the client...
Read more >What is a 4XX Error? | 4XX HTTP Codes with Explanation
4XX error codes are designed to inform a client that a problem has arisen on their end. Here are explain common 4XX HTTP...
Read more >5xx Server Errors | What are they and how to fix them
Here, we will focus on the 5xx HTTP responses. You will learn what this code means, the most common causes, how to detect...
Read more >HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
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 FreeTop 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
Top GitHub Comments
idea: per req config
add a property or method to the
superagent.Request
class e.g addRequest.prototype.config
I’m 👍 on this too
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