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

JSONRPCError cannot be caught with instanceof #209

Closed
layday opened this issue Aug 26, 2020 · 1 comment · Fixed by #234
Closed

JSONRPCError cannot be caught with instanceof #209

layday opened this issue Aug 26, 2020 · 1 comment · Fixed by #234
Assignees
Labels
bug Something isn't working released

Comments

@layday
Copy link

layday commented Aug 26, 2020

The following will not work:

try {
  const foo = await someRpcMethodWhichThrows();
} catch (error) {
  if (error instanceof JSONRPCError) {
      // no cigar
   }
}

Apparently extend doesn't really extend errors when transpiling to ES5 (like you are doing) and to subclass an error that can be 'caught' with instanceof you have to restore its prototype chain by adding Object.setPrototypeOf(this, new.target.prototype) somewhere in the constructor. Please refer to https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work and https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget.

@shanejonas shanejonas self-assigned this Dec 17, 2020
@shanejonas shanejonas added the bug Something isn't working label Dec 17, 2020
shanejonas added a commit that referenced this issue Dec 17, 2020
shanejonas added a commit that referenced this issue Dec 17, 2020
openrpc-bastion added a commit that referenced this issue Dec 17, 2020
## [1.6.2](1.6.1...1.6.2) (2020-12-17)

### Bug Fixes

* **RequestManager:** ignore missing id ([6bc8116](6bc8116))
* jsonrpc error instanceof ([c85f501](c85f501)), closes [#209](#209)
* this corrects default timeout to be disabled by specifing null. ([c79d213](c79d213)), closes [#231](#231)
@openrpc-bastion
Copy link
Member

🎉 This issue has been resolved in version 1.6.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants