cosmjs icon indicating copy to clipboard operation
cosmjs copied to clipboard

Make http function fail when backend not available

Open webmaster128 opened this issue 4 years ago • 1 comments

This function does not reject when the target is not available, leading to strange errors down the line.

async function http(method: "POST", url: string, request?: any): Promise<any> {
  if (typeof fetch !== "undefined") {
    const body = request ? JSON.stringify(request) : undefined;
    return fetch(url, { method: method, body: body })
      .then(filterBadStatus)
      .then((res: any) => res.json());
  } else {
    return axios.request({ url: url, method: method, data: request }).then((res) => res.data);
  }
}

This happens when executing the SLOW_SIMAPP_ENABLED test with not slow simd started.

webmaster128 avatar Jul 28 '21 13:07 webmaster128

The observed behaviour is probably coming from websocket connections not http because the only slow simapp test uses websockets:

    it("respects user timeouts rather than RPC timeouts", async () => {
      pendingWithoutSlowSimapp();
      const client = await StargateClient.connect(slowSimapp.tendermintUrl);
      const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic);
      const [{ address, pubkey: pubkeyBytes }] = await wallet.getAccounts();
      // ...

webmaster128 avatar Oct 11 '21 22:10 webmaster128