GithubHelp home page GithubHelp logo

Comments (7)

sindresorhus avatar sindresorhus commented on May 18, 2024 1

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.

fregante avatar fregante commented on May 18, 2024

The good part is that name is preserved as 'MyError' even though it's not an instance of it.

from serialize-error.

sindresorhus avatar sindresorhus commented on May 18, 2024

Good idea πŸ‘

from serialize-error.

fregante avatar fregante commented on May 18, 2024

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.

fregante avatar fregante commented on May 18, 2024

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.

StevenLangbroek avatar StevenLangbroek commented on May 18, 2024

Hey @sindresorhus! Would you be open to another PR adding support for AggregateError?

from serialize-error.

fregante avatar fregante commented on May 18, 2024

You can open a new issue. Given it’s a complex error, it first needs proper serialization support.

from serialize-error.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.