cosmjs
cosmjs copied to clipboard
Make http function fail when backend not available
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.
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();
// ...