chargebee / chargebee-typescript

Typescript library for the Chargebee API.
https://apidocs.chargebee.com/docs/api?lang=typescript
MIT License
22 stars 16 forks source link

Issue handling errors when Chargebee is down #24

Closed Rohland closed 2 years ago

Rohland commented 2 years ago

This evening on 15 December 2021, Chargebee is down throwing a 503.

Response is:

<head><title>503 Service Temporarily Unavailable</title></head>

Despite error handling in place, our services are crashing because of a bug in processing responses in core.ts. See below:

https://github.com/chargebee/chargebee-typescript/blob/d0a0bc6173c996d654ec2dee7914b077d622104b/src/core.ts#L25-L33

Error thrown is:

TypeError: Cannot create property 'http_status_code' on string '... on line 32

It looks like the response is a valid JSON string and is being parsed appropriately, however, an assumption has been made that the result is an object which can be extended.

An appropriate type check is required to validate the response type is indeed an object.

cfbender commented 2 years ago

Came to write the same issue. The parse is indeed failing, however the catch block does not return, and the function goes on to treat it as a valid object. I believe return Core.throwError(.. is possibly the expected behavior.

cb-yateshmathuria commented 2 years ago

This has been addressed in v2.4.1.