createBankTransactionAttachmentByFileName hangs on non-JSON response from Xero API

Abierto
#479 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
javascript, nodejs, typescript
Área
api

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
264
Forks
177
Merge medio
10 h 5 min
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de XeroAPI/xero-node

Todos los issues de XeroAPI/xero-node

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.