Skip to content

Commit

Permalink
Move log_error call to #send_failsafe method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon de Andres committed Sep 14, 2015
1 parent afb48ab commit e81d5fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
17 changes: 11 additions & 6 deletions lib/rollbar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,11 @@ def do_write_payload(payload)
end

def send_failsafe(message, exception)
body = failsafe_body(message, exception)
exception_reason = failsafe_reason(message, exception)

log_error "[Rollbar] Sending failsafe response due to #{exception_reason}"

body = failsafe_body(exception_reason)

failsafe_data = {
:level => 'error',
Expand Down Expand Up @@ -605,9 +609,8 @@ def send_failsafe(message, exception)
failsafe_payload
end

def failsafe_body(message, exception)
body = 'Failsafe from rollbar-gem. '
log_error "[Rollbar] Sending failsafe response due to #{message}."
def failsafe_reason(message, exception)
body = ''

if exception
begin
Expand All @@ -618,8 +621,6 @@ def failsafe_body(message, exception)
exception_info += " in #{nearest_frame}" if nearest_frame

body += "#{exception_info}: #{message}"

log_error "[Rollbar] #{body}"
rescue
end
else
Expand All @@ -632,6 +633,10 @@ def failsafe_body(message, exception)
body
end

def failsafe_body(reason)
"Failsafe from rollbar-gem. #{reason}"
end

def schedule_payload(payload)
return if payload.nil?

Expand Down
10 changes: 8 additions & 2 deletions spec/rollbar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1586,14 +1586,20 @@ def backtrace

context 'if the exception has a backtrace' do
let(:backtrace) { ['func3', 'func2', 'func1'] }
let(:failsafe_reason) { 'StandardError in func3: test failsafe' }
let(:expected_body) { "Failsafe from rollbar-gem. #{failsafe_reason}" }
let(:expected_log_message) do
"[Rollbar] Sending failsafe response due to #{failsafe_reason}"
end

before { exception.set_backtrace(backtrace) }

it 'adds the nearest frame to the message' do
expect(notifier).to receive(:log_error).with(expected_log_message)

sent_payload = notifier.send(:send_failsafe, "test failsafe", exception)

expected_message = 'Failsafe from rollbar-gem. StandardError in func3: test failsafe'
expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_message)
expect(sent_payload['data'][:body][:message][:body]).to be_eql(expected_body)
end
end
end
Expand Down

0 comments on commit e81d5fc

Please sign in to comment.