Agent readState

Can anyone help me to readState I got this error

Blockquote
Unhandled Rejection (Error): Server returned an error:
Code: 422 (Unprocessable Entity)
Body: Could not parse body as read request: invalid type: null, expected a sequence
Blockquote

Blockquoteconst agent = new HttpAgent({
host: this.state.host,
principal
});
agent.addTransform(makeNonceTransform());
agent.addTransform(makeExpiryTransform(5 * 60 * 1000));
agent.status();

    let { requestId, response } = await agent.call(this.state.customers_candid, {
        methodName: 'addProfile',
        arg: idl  //"DIDL\0\0", //CANDID_ENCODED_ARGUMENT_GOES_HERE //BinaryBlob
    });

    if (!response.ok)
        throw new Error(
        "could not contact the replica. error: " + response.statusText
        );
    
    console.log(`requestId`,requestId);
    console.log(`response`, response);

     while (true) {
         **const status = await agent.readState(agent.getPrincipal())**
         console.log(status.status);
        
        // eslint-disable-next-line default-case
        switch (status.status) {
        case RequestStatusResponseStatus.Replied: {
                await this.clearInput();
                const ResponseReplied = status.reply.arg;
                console.log(`Replied encoded : `, ResponseReplied);
                const idlDecod =  new IDL.decode([], ResponseReplied)
                console.log(`Replied decoded`, idlDecod);
            return new Uint8Array(status.reply.arg || []);
        }
        case RequestStatusResponseStatus.Unknown:
        case RequestStatusResponseStatus.Received:
        case RequestStatusResponseStatus.Processing:
            continue;
        case RequestStatusResponseStatus.Rejected:
            throw new Error(
            "call was rejected. reason: " + status.reject_message
            );
        case RequestStatusResponseStatus.Done:
            throw new Error(
            "call was done without a return value. this is an error"
            );
        default:
            throw new Error(
            "status is " + status.
        );
        }
     }
1 Like