I wrote the following code in Motoko (is it correct?):
/// Call methods in the given order and don't return.
///
/// If a method is missing, keep calling other methods.
public shared({caller}) func callIgnoringMissing(methods: [{canister: Principal; name: Text; data: Blob}]): () {
onlyOwner(caller);
for (method in methods.vals()) {
try {
ignore await IC.call(method.canister, method.name, method.data);
}
catch (e) {
if (Error.code(e) != #call_error {err_code = 302}) { // CanisterMethodNotFound
throw e; // Other error cause interruption.
}
}
};
};
Now I am trying to rewrite everything in Rust:
#[update(guard = onlyOwner)]
fn callIgnoringMissing(methods: Vec<Call>) {
spawn(async {
for method in methods {
if let Err((code, s)) = call_raw(method.canister, &method.name, &method.data, 0).await {
if code != RejectionCode(302) { // CanisterMethodNotFound
return;
}
}
}
});
}
But it can’t work, because there is no rejection code 302.
Please help (it is really important for me), to write a Rust function that calls an array of shared methods skipping missing methods.