question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to config the 4xx & 5xx statusCode as normal response but not error

See original GitHub issue

As 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:19 (13 by maintainers)

github_iconTop GitHub Comments

5reactions
magicdawncommented, Oct 10, 2016

idea: per req config

add a property or method to the superagent.Request class e.g add Request.prototype.config

request
  .get('https://www.google.com.hk')
  .config({ detectStatusCode: false }) //  <- turn off detectStatusCode here
  .end((err, res) => {
    // ... blabla
  });

I’m 👍 on this too

3reactions
kornelskicommented, Sep 18, 2016

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(…)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found