createBankTransactionAttachmentByFileName hangs on non-JSON response from Xero API
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
createBankTransactionAttachmentByFileNamesaves files by calling Xero API - i.e.https://api.xero.com/api.xro/2.0/BankTransactions/**id-redacted**/Attachments/h3h33sjg-rec.jpg- 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>
- 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
@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.