createBankTransactionAttachmentByFileName hangs on non-JSON response from Xero API

Ouverte
#479 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
25/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Domaine
api

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
TypeScript
Étoiles
264
Forks
177
Merge moyen
10 h 5 min
PR mergées (30 j)
5

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de XeroAPI/xero-node

Toutes les issues de XeroAPI/xero-node

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.