Skip to content

Commit

Permalink
Merge pull request #208 from hsong-rh/fix_error_logs
Browse files Browse the repository at this point in the history
Fixed to log error messages in with_request block
  • Loading branch information
eclarizio authored Oct 1, 2020
2 parents 3a5da59 + 64057f6 commit 00cf1d3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def self.included(other)
end

def rescue_from_handler(exception)
logger.error("#{exception.class.name}: #{exception.message}\n#{exception.backtrace.join("\n")}")
errors = Insights::API::Common::ErrorDocument.new.tap do |error_document|
exception_list_from(exception).each do |exc|
if api_client_exception?(exc)
Expand Down
3 changes: 3 additions & 0 deletions lib/insights/api/common/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def self.with_request(request)
self.current = request
self.current_request_id = current&.request_id
yield current
rescue => exception
Rails.logger.error("#{exception.class.name}: #{exception.message}\n#{exception.backtrace.join("\n")}")
raise
ensure
self.current = saved
self.current_request_id = saved_request_id
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/insights/api/common/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@
end

it 'with an invalid Hash' do
expect(Rails.logger).to receive(:error).with(/ArgumentError: /).once

expect do
described_class.with_request({}) {}
end.to raise_exception(ArgumentError)
Expand Down

0 comments on commit 00cf1d3

Please sign in to comment.