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

Update call rejection should produce UpdateCallRejectedError instead of text error #737

Open
AndyGura opened this issue Jul 11, 2023 · 1 comment
Assignees

Comments

@AndyGura
Copy link

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:

throw new Error(
`Call was rejected:\n` +
` Request ID: ${toHex(requestId)}\n` +
` Reject code: ${rejectCode}\n` +
` Reject text: ${rejectMessage}\n`,
);

I believe instance of UpdateCallRejectedError should be thrown instead for more convenient error-handling in top-level application

To Reproduce

  1. Create and deploy motoko canister:
import Error "mo:base/Error";

actor class Test() {
  public shared func err() : async () {
    throw Error.reject("Rejected message");
  };
};
  1. Create agent-js actor for it
  2. Write test code:
try {
    await actor.err();
} catch (err) {
    console.log(err instanceof UpdateCallRejectedError);
}
  1. 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.

@krpeacock
Copy link
Contributor

I've reviewed this issue and added it to my queue. Thanks for reporting!

@krpeacock krpeacock self-assigned this Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants