call

tcmts.cli.test.e2e.data.call · #22oupb2r · term · runs anywhere

POST a server function call, retried once on a keep-alive connection reset (see web.test.ts).

export const call = async (url: string, hash: string, args: unknown[]): Promise<{ status: number; body: string }> => {
  const init = { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(args) };
  let r: Response;
  try {
    r = await fetch(new URL(`/__tcm/rpc/${hash}`, url), init);
  } catch (e) {
    if ((e as { cause?: { code?: string } }).cause?.code !== "ECONNRESET") throw e;
    r = await fetch(new URL(`/__tcm/rpc/${hash}`, url), init);
  }
  return { status: r.status, body: await r.text() };
}

used by