XeroAPI / xero-node

Xero Node SDK for OAuth 2.0 generated from XeroAPI/Xero-OpenAPI
http://developer.xero.com/
MIT License
205 stars 162 forks source link

createBankTransactionAttachmentByFileName hangs on non-JSON response from Xero API #479

Open stepanh opened 3 years ago

stepanh commented 3 years ago

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

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

stepanh commented 3 years ago

@RettBehrens , @SerKnight - I'm now aware of one case that causes Xero API to throw the 500 Internal Server Error - file name that contains #. Where should that be reported?

This is still an issue in v4.11.2. I think the generator code for this is https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache . It seems to me that the parsing code body = JSON.parse(body) was moved elsewhere, so this might be fixed in master - but not sure.