Comments (7)
Sure. I don't think it should contain the built-in error types though. We don't want users to be able to remove those. So maybe it should be named customErrorClasses
? I would go with Set
. It's the correct data structure for this.
from serialize-error.
The good part is that name
is preserved as 'MyError'
even though it's not an instance of it.
from serialize-error.
Good idea π
from serialize-error.
I think this could have an internal list of known constructors that could be extended/overridden by the user. Some can be found at: https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/error
Actually supporting all those error correctly might not be possible, but a plain if error.name === TypeError.name, then new TypeError(error.message)
would go a long way.
from serialize-error.
What do you think about exporting a global set of supported errors? This would avoid having to manually pass this around (and potentially forget to), as well enabling support across modules (and sub dependencies)
import {errorClasses} from 'serialize-error';
errorClasses.push(MyError, CoolError, APIError);
π Maybe an array is better because Set
does not allow adding multiple items (or an array) at once.
from serialize-error.
Hey @sindresorhus! Would you be open to another PR adding support for AggregateError
?
from serialize-error.
You can open a new issue. Given itβs a complex error, it first needs proper serialization support.
from serialize-error.
Related Issues (20)
- Error: Cannot read property 'pipe' of null
- Version 9.1.1 with CRA default Babel config gives "Module parse failed" HOT 1
- Jest encountered an unexpected token HOT 1
- Optionally ignore `toJSON` HOT 2
- `toJSON` example is confusing
- Handle custom error constructors with incompatible signatures
- Nested errors are still not serialized
- Unknown object type "asyncfunction" HOT 3
- `deserializeError` serializes/destroys properties unnecessarily HOT 1
- Wrong typescript declaration for errorConstructors HOT 6
- Wrong typescript definition for serializeError HOT 4
- Jest encounters `SyntaxError: Cannot use import statement outside a module` while trying to test code that uses `serialize-error` HOT 8
- If string is passed as unknown, the value returned from serializeError is badly typed as ErrorObject HOT 1
- Error require of ES Module not supported HOT 21
- Visibility of undefined values in the objects
- Enumerable properties are made non-enumerable
- Keep old versions of the lib on a separate branch HOT 1
- `option` to treat undefined as null HOT 1
- Received error object is not extensible when calling serialize error
- ERR_REQUIRE_ESM HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serialize-error.