forwardemail / forwardemail/superagent

Documentation for response error handling outdated?

Open
#1,044 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
16.6k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

According to the docs, when there is an error (eg. 404), I have to obtain the error using "err.status".
http://visionmedia.github.io/superagent/#error-handling

```
if (err && err.status === 404) {
alert('oh no ' + res.body.message);
}
```

However, when I tried to make a 404 error, "err" only shows a text-based message, doesn't seem like an object.

Here is what I get from console.log()

```
Error: Not Found
at Request. (http://localhost/codebase/assets/portal/js/vendor.js:76987:19)
at Request.Emitter.emit (http://localhost/codebase/assets/portal/js/vendor.js:5623:20)
at XMLHttpRequest.xhr.onreadystatechange (http://localhost/codebase/assets/portal/js/vendor.js:77258:10)
```

I know I can get that status information in "res", but the above is not the purpose my current task. It is though a factor I must consider before I decide on my approach. I would like to understand how it functions completely (including border line cases) before I start writing my code. I found that it doesn't quite work like the documentation suggests.
#

This also doesn't work as documented I think. The 404 error doesn't seem to come into here, though it does trigger "end()" callback method:

```
.on('error', function(err) {
console.log('Error: ', res, err);
})
```
#

May I ask if the doc is outdated or something? Or if I completely misunderstood, please do let me know.

Your help is appreciated. Thanks!

Cheers,
Thomas

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.