Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't rely on classes for error handling #331

Closed
vgrichina opened this issue May 26, 2020 · 0 comments · Fixed by #570
Closed

Don't rely on classes for error handling #331

vgrichina opened this issue May 26, 2020 · 0 comments · Fixed by #570
Assignees
Labels
enhancement New feature or request P2 Pretty important

Comments

@vgrichina
Copy link
Contributor

Currently structured errors are represented by custom TypeScript classes for every error type. This has few drawbacks:

  • checking if smth is instance of type is unreliable in JS. It breaks down easily once there are multiple versions of library in given environment, similar to problems with serialization (see Switch to use strings for serialization naming #330)
  • a lot of boilerplate (including some code gen) is necessary to support this
  • every time nearcore introduces new error types – there is a need to do codegen, make new near-api-js release, etc

Given dynamic nature of JS we would be better of just doing generic TypedError with following fields:

  • type – error type string. Used to check which type of error it is.
  • data – whatever detailed data JSON object attached to error. Used as parameters when formatting errors for UI, etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P2 Pretty important
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants