Update call rejection should produce `UpdateCallRejectedError` instead of text error
Describe the bug
Though agent-js declares error UpdateCallRejectedError, it cannot be caught in the wild, since initial http response from canister (always?) looks like this:
{
"ok": true,
"status": 202,
"statusText": "Accepted"
}
And therefore if I write throw Error.reject or Debug.trap in canister, it will be processed by polling and produce pure text error here: https://github.com/dfinity/agent-js/blob/8254c47694c1286058a8293547bda98a6d19c8e1/packages/agent/src/polling/index.ts#L68-L73
I believe instance of UpdateCallRejectedError should be thrown instead for more convenient error-handling in top-level application
To Reproduce
- Create and deploy motoko canister:
import Error "mo:base/Error";
actor class Test() {
public shared func err() : async () {
throw Error.reject("Rejected message");
};
};
- Create agent-js actor for it
- Write test code:
try {
await actor.err();
} catch (err) {
console.log(err instanceof UpdateCallRejectedError);
}
- Observe
falsein console and check that error contains only plain text message
Expected behavior
UpdateCallRejectedError instance should be caught with all the appropriate fields in it.
I've reviewed this issue and added it to my queue. Thanks for reporting!