createBankTransactionAttachmentByFileName hangs on non-JSON response from Xero API

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, nodejs, typescript
Ambito
api

Direzione di ricerca

The failing parse is in the compiled dist/gen/api/accountingApi.js inside the request callback of createBankTransactionAttachmentByFileName, where JSON.parse(body) runs unguarded. The code is generated from the XeroAPI/Xero-OpenAPI spec, so the fix may belong in the generator templates rather than the output. Done means a non-JSON response such as an nginx 500 page rejects the promise with an error instead of hanging. Check first whether the upstream generator already handles this, since the issue has been stale for years.

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

Descrizione

SDK you're using (please complete the following information):

  • Version 4.9.1

Describe the bug
createBankTransactionAttachmentByFileName hangs when it receives non-JSON response from Xero API. uncaughtException is triggered, but Promise never resolves or rejects.

To Reproduce

  1. createBankTransactionAttachmentByFileName saves files by calling Xero API - i.e.https://api.xero.com/api.xro/2.0/BankTransactions/**id-redacted**/Attachments/h3h33sjg-rec.jpg
  2. However this endpoint sometimes fails and returns this body. (I tried saving this same file about 10 times, in the same way, the endpoint was failing and then succeeded on the last try.)
<html>
<head><title>500 Internal Server Error</title></head>
<body>
<center><h1>500 Internal Server Error</h1></center>
<hr><center>nginx</center>
</body>
</html>
  1. When bad body is received, it fails to parse to JSON - this line fails: body = JSON.parse(body)
SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Request._callback (/node_modules/xero-node/dist/gen/api/accountingApi.js:310:41)

Expected behavior
Well, Xero API shouldn't be failing to save files in the first place. But when it does fail, xero-node should catch JSON parse error and call reject.

Additional context
Happy to provide failing transactionIDs, etc. on request

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.