Skip to content

[Bug] newHttpBatchRpcSession RequestInit param is silently ignored #67

@jahands

Description

@jahands

The signature in src/index.ts looks like this:

export let newHttpBatchRpcSession:<T extends Serializable<T>>
    (urlOrRequest: string | Request, init?: RequestInit) => RpcStub<T> =
    <any>newHttpBatchRpcSessionImpl;

But the implementation in src/batch.ts takes RpcSessionOptions, not RequestInit:

export function newHttpBatchRpcSession(
    urlOrRequest: string | Request, options?: RpcSessionOptions): RpcStub {
  let sendBatch: SendBatchFunc = async (batch: string[]) => {
    let response = await fetch(urlOrRequest, {
      method: "POST",
      body: batch.join("\n"),
    });

    if (!response.ok) {
      response.body?.cancel();
      throw new Error(`RPC request failed: ${response.status} ${response.statusText}`);
    }

    let body = await response.text();
    return body == "" ? [] : body.split("\n");
  };

  let transport = new BatchClientTransport(sendBatch);
  let rpc = new RpcSession(transport, undefined, options);
  return rpc.getRemoteMain();
}

I found this rather confusing to debug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions