diff --git a/packages/agent/src/actor.ts b/packages/agent/src/actor.ts index 72ed8c8e..cc588e41 100644 --- a/packages/agent/src/actor.ts +++ b/packages/agent/src/actor.ts @@ -6,9 +6,9 @@ import { QueryResponseRejected, QueryResponseStatus, ReplicaRejectCode, - SubmitResponse, + SubmitResponse, v2ResponseBody, v3ResponseBody, -} from './agent'; +} from "./agent"; import { AgentError } from './errors'; import { bufFromBufLike, IDL } from '@dfinity/candid'; import { pollForResponse, PollStrategyFactory, strategy } from './polling'; @@ -582,6 +582,19 @@ function _createActorMethod( } } } + + // handle v2 response errors by throwing an UpdateCallRejectedError object + if (!response.ok || response.body /* IC-1462 */) { + const { reject_code, reject_message, error_code } = response.body as v2ResponseBody; + throw new UpdateCallRejectedError(cid, + methodName, + requestId, + response, + reject_code, + reject_message, + error_code) + } + // Fall back to polling if we receive an Accepted response code if (response.status === 202) { const pollStrategy = pollingStrategyFactory(); diff --git a/packages/agent/src/certificate.ts b/packages/agent/src/certificate.ts index d9ff728e..1f537478 100644 --- a/packages/agent/src/certificate.ts +++ b/packages/agent/src/certificate.ts @@ -272,19 +272,17 @@ export class Certificate { await cert.verify(); - if (this._canisterId.toString() !== MANAGEMENT_CANISTER_ID) { - const canisterInRange = check_canister_ranges({ - canisterId: this._canisterId, - subnetId: Principal.fromUint8Array(new Uint8Array(d.subnet_id)), - tree: cert.cert.tree, - }); - if (!canisterInRange) { - throw new CertificateVerificationError( - `Canister ${this._canisterId} not in range of delegations for subnet 0x${toHex( - d.subnet_id, - )}`, - ); - } + const canisterInRange = check_canister_ranges({ + canisterId: this._canisterId, + subnetId: Principal.fromUint8Array(new Uint8Array(d.subnet_id)), + tree: cert.cert.tree, + }); + if (!canisterInRange) { + throw new CertificateVerificationError( + `Canister ${this._canisterId} not in range of delegations for subnet 0x${toHex( + d.subnet_id, + )}`, + ); } const publicKeyLookup = lookupResultToBuffer( cert.lookup(['subnet', d.subnet_id, 'public_key']),