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

How to handle 500 errors with Rest API #1119

Closed
colinbrogan opened this issue Mar 3, 2023 · 2 comments
Closed

How to handle 500 errors with Rest API #1119

colinbrogan opened this issue Mar 3, 2023 · 2 comments

Comments

@colinbrogan
Copy link

Hi,
I am using 12.4.0 version of this gem.
Every once in a while, I get a 500 error from what should be a valid REST request to Shopify's API. The request retrieves metafields from a product. The reason I know this request is valid, is because if I run the same script on 500 products multiple times, it will sometimes make it all the way through, other times fail on a random product, each time a different product.

I understand that no server has perfect uptime (assuming that is the problem). However,
your gem is producing the errors pretty deep in it's libraries, so I am not given a clean way to do any error management with begin rescue or the like. Below is the response I am given:

/home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/json-2.6.3/lib/json/common.rb:216:in parse': unexpected token at '<!-- (JSON::ParserError)`

Then below that is a whole bunch of html describing a 500 error page which says "There was a problem loading this website". I omit it here for brevity. Then the backtrace shows all of this, before getting into my app:

/home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/json-2.6.3/lib/json/common.rb:216:inparse'
/home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/json-2.6.3/lib/json/common.rb:216:in parse' /home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/shopify_api-12.4.0/lib/shopify_api/clients/http_client.rb:51:in request'
/home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sorbet-runtime-0.5.10672/lib/types/private/methods/call_validation_2_7.rb:106:in bind_call' /home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sorbet-runtime-0.5.10672/lib/types/private/methods/call_validation_2_7.rb:106:in block in create_validator_method_fast1'
/home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/shopify_api-12.4.0/lib/shopify_api/clients/rest/admin.rb:25:in get' /home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sorbet-runtime-0.5.10672/lib/types/private/methods/call_validation.rb:153:in bind_call'
/home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sorbet-runtime-0.5.10672/lib/types/private/methods/call_validation.rb:153:in validate_call_skip_block_type' /home/colinbrogan/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sorbet-runtime-0.5.10672/lib/types/private/methods/call_validation.rb:95:in block in create_validator_slow_skip_block_type'
`

What seems obvious here is that the library is not catching the 500 error, and tries to parse an html error-page response as if it were JSON (which it isn't). I need a way to catch this error, and know what kind it is (internal server error? Over API bucket limit? Invalid request?).

@ClaytonPassmore
Copy link
Contributor

ClaytonPassmore commented Mar 16, 2023

Unfortunately this is an ongoing issue. See here:

It should be fixed by #1113 but the repo maintainers haven't look at it yet.

@nelsonwittwer
Copy link
Contributor

We are on it! I will close this issue as it as duplicate of #1091. thanks for your patience on this!

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

No branches or pull requests

3 participants