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

Aperta
#850 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
Mezza giornata
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
nodejs, typescript
Ambito
api

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
TypeScript
Stelle
264
Fork
177
Merge medio
10h 5m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di XeroAPI/xero-node

Tutte le issue di XeroAPI/xero-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.