Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection failure raises "TypeError: Server responded with invalid JSON" #101

Open
ivanbrennan opened this issue May 26, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@ivanbrennan
Copy link

Describe the bug
Occasionally, an API request fails due to an intermittent network error, and the SDK raises a TypeError when attempting to parse the error response as JSON. An example error I've observed had the following response body:

upstream connect error or disconnect/reset before headers. reset reason: connection failure

Expected behavior
I'm not sure how best to handle this scenario, but I think raising a more semantically-meaningful error would be preferable, as that would help clients implement reasonable error-handling.

To Reproduce
Because this is caused by intermittent network failures, I'm not sure how to reliably reproduce the issue.

Backtrace
Here's an extract from the backtrace of such an error:

/gems/square.rb-19.0.0.20220420/lib/square/api_helper.rb:130 in rescue in json_deserialize
/gems/square.rb-19.0.0.20220420/lib/square/api_helper.rb:127 in json_deserialize
/gems/square.rb-19.0.0.20220420/lib/square/api/cards_api.rb:58 in list_cards

Caused by JSON::ParserError: 783: unexpected token at 'upstream connect error or disconnect/reset before headers. reset reason: connection failure'

Square SDK version
19.0.0.20220420

@wolfadex
Copy link
Contributor

wolfadex commented Jun 6, 2022

Thank you for your feedback @ivanbrennan. Improved error messages is something we have on our roadmap for 2022.

@wolfadex wolfadex added the enhancement New feature or request label Jun 6, 2022
@dawoodmalhi
Copy link

I have also encountered the same error while making the complete_payment API call with payment_id as nil. Just want to know, Is it going to be handled in near future.

@pelletencate
Copy link

Hey @wolfadex, any update on this? We just got this exact exception on various occasions where the Square API returns a HTML page instead of a valid JSON response. Last time I've seen it was a very normal request that we were able to replay without any problems (finding a Square gift card by GAN)

@zenmasterjobo
Copy link

hi @pelletencate - which version of the ruby SDK are you using?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants