Skip to content

Commit

Permalink
Documented getErrContext
Browse files Browse the repository at this point in the history
  • Loading branch information
miraclx committed Feb 10, 2020
1 parent e8c0863 commit 6cb13c5
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,31 @@ xget(URL)
.pipe(createWriteStreamSomehow());
```

### <a id='xgetgeterrcontext'></a> xget.getErrContext(err)

* `err`: &lt;[Error][]&gt;
* Returns: &lt;[Object][]&gt;
* `raw`: &lt;[Error][]&gt;
* `tag`: &lt;[string][]&gt; The tag of the middleware function as defined.
* `source`: &lt;`'xget:with'`&gt; | &lt;`'xget:use'`&gt; The type of middleware from which the error was emitted.

Extract data from an error if it was either thrown from within a [UseMiddlewareFn](#usemiddlewarefn) or a [WithMiddlewareFn](#withmiddlewarefn) function.

``` javascript
xget(URL)
.use('errorThrower', () => {
throw new Error('Custom error being thrown');
})
.once('error', err => {
const ({tag, source}) = xget.getErrContext(err);
if (source)
console.log(`Error thrown from within the [${tag}] method of the [${source}] middlware`);
// Error thrown from within the [errorThrower] method of the [xget:use] middleware
})
.pipe(createWriteStreamSomehow());

```

### <a id='loaddata'></a> LoadData: [`Object`][object]

* `url`: &lt;[string][]&gt; The URL specified.
Expand Down

0 comments on commit 6cb13c5

Please sign in to comment.