GET requests send `data: {}`, which fetch-based runtimes reject

未关闭
#850 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
半天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
nodejs, typescript
领域
api

调研方向

Start with the generated GET methods such as AccountingApi.getContact and getContacts, where request options are built with data: {}, and with the applyToRequest authentication hook the issue uses as a workaround. Check whether the fix belongs in the generated client or in the generator templates, since the issue does not say. Done means GET and HEAD requests omit data and a fetch-adapter test or a nock test passes for a GET call.

由索引模型根据 Issue 内容生成。

描述

SDK you're using: xero-node 20.0.0 (same in 10.2.0 through 19.3.0), axios 1.19.0, Cloudflare Workers

Describe the bug

Every generated GET method (e.g. AccountingApi.getContact, getContacts, getInvoices) builds its request options with data: {}. axios serializes that to a "{}" body. Node's http adapter tolerates it, but on runtimes where axios uses its fetch adapter (Cloudflare Workers, and anywhere Request follows the Fetch spec), creating the Request throws:

TypeError: Request with a GET or HEAD method cannot have a body.

So no GET call works on Workers, even after the token request succeeds.

Expected behavior

Requests without a body parameter omit data (or set it to undefined).

Workaround

Replace the default authentication hook, which runs on each request just before axios sends it:

xero.accountingApi.setDefaultAuthentication({
  applyToRequest: (options) => {
    if (options.method === 'GET' || options.method === 'HEAD') delete options.data;
  },
});

Related: #737 (same cause, seen through nock), #740 (fetch adapter support).

主要语言
TypeScript
星标
264
派生
177
平均合并
10 小时 5 分钟
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

XeroAPI/xero-node 的其他 Issue

查看 XeroAPI/xero-node 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。