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

オープン
#850 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

XeroAPI/xero-node のほかの issue

XeroAPI/xero-node の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。