forwardemail / forwardemail/superagent

Feature request: use a unique Error type for operational errors

Open
#864 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

I think it's great that superagent embraces the Error object, but it would be cool if there were an easy way to tell if an error originated from Superagent. This is useful for standardizing error reporting in an application: for example, I can do something like:

```
if (error instanceof SuperagentError) {
// collect information from error object and log it somewhere
}
```

Of course, I can do duck-typing and look for properties like `timeout` or `response` on the error, but this introduces a conflict with other errors that might use those properties.

My suggestion: operational errors should be of type `SuperagentError` rather than `Error`. This type should be exported in the package for easy comparison (and set on the global object for people not using a module loader).

Happy to write a PR if this is a desired feature.

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.