createBankTransactionAttachmentByFileName hangs on non-JSON response from Xero API

Đang mở
#479 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Lĩnh vực
api

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
TypeScript
Star
264
Fork
177
Merge trung bình
10 giờ 5 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của XeroAPI/xero-node

Tất cả issue của XeroAPI/xero-node

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.