Skip to content

Commit

Permalink
correctly catch and log exceptions from CloudRequestForwarder
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Feb 13, 2025
1 parent 9fa6578 commit b7cbb6e
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ class MachineTelemetriesController < ::Api::V2::BaseController
# The method that "proxies" requests over to Cloud
def forward_request
certs = candlepin_id_cert @organization
@cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
begin
@cloud_response = ::ForemanRhCloud::CloudRequestForwarder.new.forward_request(request, controller_name, @branch_id, certs)
rescue RestClient::Exception => general_exception

Check failure on line 21 in app/controllers/insights_cloud/api/machine_telemetries_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Naming/RescuedExceptionsVariableName: Use `e` instead of `general_exception`.
logger.info("Forwarding request failed with exception: #{general_exception}")
return render json: { error: general_exception }, status: :bad_gateway
rescue RestClient::Timeout => timeout_exception

Check failure on line 24 in app/controllers/insights_cloud/api/machine_telemetries_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop / Rubocop

Naming/RescuedExceptionsVariableName: Use `e` instead of `timeout_exception`.
logger.info("Forwarding request failed with timeout: #{timeout_exception}")
return render json: { error: timeout_exception }, status: :gateway_timeout
end

if @cloud_response.code == 401
return render json: {
Expand Down

0 comments on commit b7cbb6e

Please sign in to comment.