Update call rejection should produce `UpdateCallRejectedError` instead of text error
AndyGura opened this issue · comments
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:
agent-js/packages/agent/src/polling/index.ts
Lines 68 to 73 in 8254c47
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
false
in 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!