-
Notifications
You must be signed in to change notification settings - Fork 33
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
only return response from Exceptions that have it #940
base: develop
Are you sure you want to change the base?
Conversation
Only RestClient::ExceptionWithResponse has .response, while a "normal" RestClient::Exception does not. But by catching RestClient::Exception we might swallow errors that would be useful for users in the logs, like RestClient::SSLCertificateNotVerified
compare to e.g. foreman_rh_cloud/lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb Lines 45 to 56 in d642c75
|
@@ -17,7 +17,7 @@ def forward_request(original_request, controller_name, branch_id, certs) | |||
logger.debug("Sending request to: #{request_opts[:url]}") | |||
|
|||
execute_cloud_request(request_opts) | |||
rescue RestClient::Exception => error_response | |||
rescue RestClient::ExceptionWithResponse => error_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.
Sounds good, but we need to take into account the proper reporting of errors without a response.
I suppose we will need to modify the reporting block:
foreman_rh_cloud/app/controllers/insights_cloud/api/machine_telemetries_controller.rb
Line 28 in d642c75
if @cloud_response.code >= 300 |
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.
Is that so?
That block is the whole reason I came here, as when you get a RestClient::SSLCertificateNotVerified
, that block still calls .code
but on nil
(as error_response.response
that we return here is nil
)
After the patch, it correctly raises the exception and makes it "someone elses problem" ;)
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.
It does, but the error becomes 500 which is not correct.
We need to relay the original failure to the client. That's why this block exists.
The idea is that the method always returns a result and the forwarder relays the response to the client.
I think @chris1984 is working on this already.
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.
Oooh you mean catching that exception and reporting it to the user?
yeah, that'd improve the UX, sure.
(today, you too get a 500 error, for the undefined .code
on nil
, but with the patch at least the log is useful, which it wasn't before)
Only RestClient::ExceptionWithResponse has .response, while a "normal"
RestClient::Exception does not.
But by catching RestClient::Exception we might swallow errors that would
be useful for users in the logs, like
RestClient::SSLCertificateNotVerified