Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jan 4, 2025
1 parent dc9dbcb commit 7c1116d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions error-constructors.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
Map of error constructors to recreate from the serialize `name` property. If the name is not found in this map, the errors will be deserialized as simple `Error` instances.
Let `serialize-error` know about your custom error constructors so that when `{name: 'MyCustomError', message: 'It broke'}` is found, it uses the right error constructor. If "MyCustomError" isn't found in the global list of known constructors, it defaults to the base `Error` error constructor.
Warning: Only simple and standard error constructors are supported, like `new MyCustomError(name)`. If your error constructor *requires* a second parameter or does not accept a string as first parameter, adding it to this map *will* break the deserialization.
Warning: The constructor must work without any arguments or this function will throw.
*/
declare const errorConstructors: Map<string, ErrorConstructor>;
declare function addKnownErrorConstructor(constructor: ErrorConstructor): void;

export default errorConstructors;
export {addKnownErrorConstructor};
6 changes: 3 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ console.log(unknown);
The [list of known errors](./error-constructors.js) can be extended globally. This also works if `serialize-error` is a sub-dependency that's not used directly.

```js
import {errorConstructors} from 'serialize-error';
import {addKnownErrorConstructor} from 'serialize-error';
import {MyCustomError} from './errors.js'

errorConstructors.set('MyCustomError', MyCustomError)
addKnownErrorConstructor(MyCustomError);
```

**Warning:** Only simple and standard error constructors are supported, like `new MyCustomError(message)`. If your error constructor **requires** a second parameter or does not accept a string as first parameter, adding it to this map **will** break the deserialization.
**Warning:** The constructor must work without any arguments or this function will throw.

## API

Expand Down

0 comments on commit 7c1116d

Please sign in to comment.