source: node_modules/node-domexception/.history/README_20210527212714.md@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1# DOMException
2An implementation of the DOMException class from NodeJS
3
4This package implements the [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException) class, from NodeJS itself.
5NodeJS has DOMException built in, but it's not globally available, and you can't require/import it from somewhere.
6
7The only possible way is to use some web-ish tools that have been introduced into NodeJS that throws an error and catch the constructor.
8This way you will have the same class that NodeJS has and you can check if the error is a instance of DOMException.
9The instanceof check would not have worked with a custom class such as the DOMexception provided by domenic which also is much larger in size.
10
11```js
12import DOMException from 'node-domexception'
13
14hello().catch(err => {
15 if (err instanceof DOMException) {
16 ...
17 }
18})
19
20const e1 = new DOMException("Something went wrong", "BadThingsError");
21console.assert(e1.name === "BadThingsError");
22console.assert(e1.code === 0);
23
24const e2 = new DOMException("Another exciting error message", "NoModificationAllowedError");
25console.assert(e2.name === "NoModificationAllowedError");
26console.assert(e2.code === 7);
27
28console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10);
29```
30
31## APIs
32
33This package exposes two flavors of the `DOMException` interface depending on the imported module.
34
35### `domexception` module
36
37This module default-exports the `DOMException` interface constructor.
38
39### `domexception/webidl2js-wrapper` module
40
41This module exports the `DOMException` [interface wrapper API](https://github.com/jsdom/webidl2js#for-interfaces) generated by [webidl2js](https://github.com/jsdom/webidl2js).
Note: See TracBrowser for help on using the repository browser.