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

only return response from Exceptions that have it #940

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

evgeni
Copy link
Member

@evgeni evgeni commented Jan 10, 2025

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

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
@evgeni
Copy link
Member Author

evgeni commented Jan 14, 2025

compare to e.g.

def delete_page(host_uuids, organization)
execute_cloud_request(
organization: organization,
method: :delete,
url: ForemanInventoryUpload.hosts_by_ids_url(host_uuids),
headers: {
content_type: :json,
}
)
rescue RestClient::ExceptionWithResponse => error_response
error_response.response
end
where this is done correctly

@@ -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
Copy link
Member

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:

Copy link
Member Author

@evgeni evgeni Jan 14, 2025

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" ;)

Copy link
Member

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.

Copy link
Member Author

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)

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

Successfully merging this pull request may close these issues.

2 participants