dfinity / agent-js

A collection of libraries and tools for building software around the Internet Computer, in JavaScript.
https://agent-js.icp.xyz
Apache License 2.0
151 stars 94 forks source link

instanceof check for "ActorCallError"/"QueryCallRejectedError"/"UpdateCallRejectedError" #907

Open alexeychirkov opened 1 month ago

alexeychirkov commented 1 month ago

Hey!

Is it intentional that the implementations of the ActorCallError, QueryCallRejectedError, and UpdateCallRejectedError classes do not use Object.setPrototypeOf?

The issue is that it currently prevents a type-safe check for an error thrown using this code:

try {
   myActor.notFoundQueryMethod();
} catch(e) {
   if (e instanceof QueryCallRejectedError) {
      // profit!
   }
}

The only type-safe check that works now is e instanceof AgentError, which is useless because AgentError has no properties to check.