-
Notifications
You must be signed in to change notification settings - Fork 474
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
ShopifyAPI::Clients::HttpResponse as argument for ShopifyAPI::Errors::HttpResponseError #1040
ShopifyAPI::Clients::HttpResponse as argument for ShopifyAPI::Errors::HttpResponseError #1040
Conversation
…:HttpResponseError because code can be obtained from response as well as headers for custom retry logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't normally maintain this repo but this looks good to me. I'd like to see this merged if you can sign the CLA and fix the linter.
test/clients/http_client_test.rb
Outdated
@@ -179,6 +179,18 @@ def test_throttle_error_no_retry_after_header | |||
verify_http_request | |||
end | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! Rubocop complains on this line. Care to fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
attr_reader :response | ||
|
||
sig { params(response: ShopifyAPI::Clients::HttpResponse).void } | ||
def initialize(response:) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This idea makes sense to provide the response instead of just the code!
I do think if we add the required keyword of response
we'll need to update one more place to make sure we don't introduce a regression with this change:
MaxHttpRetriesExceededError which inherits from this class. We'll need to update any instantiations of this error to reflect this keyword change otherwise we'll see an ArgumentError
anytime we raise that retries error.
Sorbet complains about a missing type annotation, this should fix it: diff --git lib/shopify_api/errors/http_response_error.rb lib/shopify_api/errors/http_response_error.rb
index 1d536a4..e4d912f 100644
--- lib/shopify_api/errors/http_response_error.rb
+++ lib/shopify_api/errors/http_response_error.rb
@@ -15,7 +15,7 @@ module ShopifyAPI
sig { params(response: ShopifyAPI::Clients::HttpResponse).void }
def initialize(response:)
super
- @code = response.code.to_i
+ @code = T.let(response.code, Integer)
@response = response
end
end You can run run the Sorbet locally with Make sure to sign the CLA too: https://cla.shopify.com/ |
|
||
raise ShopifyAPI::Errors::MaxHttpRetriesExceededError.new(code: response.code), | ||
raise ShopifyAPI::Errors::MaxHttpRetriesExceededError.new(response: response), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This idea makes sense to provide the response instead of just the code!
I do think if we add the required keyword of
response
we'll need to update one more place to make sure we don't introduce a regression with this change:MaxHttpRetriesExceededError which inherits from this class. We'll need to update any instantiations of this error to reflect this keyword change otherwise we'll see an
ArgumentError
anytime we raise that retries error.
Hi @nelsonwittwer. Thank you for your comment. Do you mean this place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added assertion for that - 3312bc0
Thank you @jbourassa for mentioning this, fixed it. We do not have sorbet in our ruby on rails project, so I'm new to this. About the CLA, my employer has asked Shopify to add additional authorized contributor to the existing Corporate CLA. We are still waiting for a reply from Shopify. |
3312bc0
to
533ec79
Compare
HI @jbourassa and @nelsonwittwer. I have CLA signed now. What are the next steps? |
@kaarelss can you rebase your branch with main? that should also get your tests to pass and we'll get this merged in |
…:HttpResponseError because code can be obtained from response as well as headers for custom retry logic
533ec79
to
c83bf0d
Compare
Done |
One last little 👶 step and we can get this merged in! Will you add a quick line in the change log describing your change? |
…y-api-ruby into response_in_error_object * 'response_in_error_object' of github.com:kaarelss/shopify-api-ruby: Added assertion that response is present in MaxHttpRetriesExceededError Added sorbet assertion Removed extra empty line ShopifyAPI::Clients::HttpResponse as argument for ShopifyAPI::Errors::HttpResponseError because code can be obtained from response as well as headers for custom retry logic Remove mentions of private apps (Shopify#1062) Fix ActiveSupport inflector dependency (Shopify#1063) Move Session Storage to `shopify_app` (Shopify#1055) Remove session argument from REST examples (Shopify#1064) Constrain Zeitwerk to 2.6.5 (Shopify#1059) Clarify statement about packages (Shopify#1057)
Added |
Hi, not sure if this is related but I wanted to try to create my own error doing the following:
Am I doing something wrong? |
Which version of the gem are you using? |
ShopifyAPI::Clients::HttpResponse as argument for ShopifyAPI::Errors::HttpResponseError because code can be obtained from response as well as headers for custom retry logic when call limit is exceeded and 429 error occurs.
Description
Fixes #1038
Please, include a summary of what the PR is for:
How has this been tested?
All tests passed as well as new test is included for this new functionality:
test_throttle_error_with_retry_after_header_in_error_object
inhttp_client_test.rb
Checklist: