@vbarbarosh/node-helpers 3.8.0 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.8.0",
5
+ "version": "3.9.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -0,0 +1,24 @@
1
+ // https://github.com/nodejs/node/issues/36084#issuecomment-729894622
2
+ class AbortError extends Error
3
+ {
4
+ constructor(message = 'The operation was aborted') {
5
+ super(message);
6
+ this.name = 'AbortError';
7
+ this.code = 'ABORT_ERR';
8
+ }
9
+
10
+ static absorb(error) {
11
+ if (AbortError.check(error)) {
12
+ return;
13
+ }
14
+ throw error;
15
+ }
16
+
17
+ static check(error) {
18
+ return error
19
+ && (error.name === 'AbortError')
20
+ && (error.code === 'ABORT_ERR');
21
+ }
22
+ }
23
+
24
+ module.exports = AbortError;