FIX: properly log webhook errors in UI on rescue (#7376)
This commit is contained in:
parent
e92cd5318b
commit
594674703c
|
@ -113,8 +113,12 @@ module Jobs
|
|||
duration: ((Time.zone.now - now) * 1000).to_i
|
||||
)
|
||||
rescue => e
|
||||
web_hook_event.update!(headers: MultiJson.dump(headers))
|
||||
Rails.logger.error("Webhook event failed: #{e}")
|
||||
web_hook_event.update!(
|
||||
headers: MultiJson.dump(headers),
|
||||
status: -1,
|
||||
response_headers: MultiJson.dump(error: e),
|
||||
duration: ((Time.zone.now - now) * 1000).to_i
|
||||
)
|
||||
end
|
||||
|
||||
MessageBus.publish("/web_hook_events/#{web_hook.id}", {
|
||||
|
|
|
@ -19,7 +19,6 @@ class WebHookEvent < ActiveRecord::Base
|
|||
else
|
||||
WebHook.last_delivery_statuses[:failed]
|
||||
end
|
||||
|
||||
web_hook.save!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -78,6 +78,20 @@ describe Jobs::EmitWebHookEvent do
|
|||
)
|
||||
end.to change { Jobs::EmitWebHookEvent.jobs.size }.by(0)
|
||||
end
|
||||
|
||||
it 'properly logs error on rescue' do
|
||||
stub_request(:post, post_hook.payload_url).to_raise("connection error")
|
||||
subject.execute(
|
||||
web_hook_id: post_hook.id,
|
||||
event_type: described_class::PING_EVENT
|
||||
)
|
||||
|
||||
event = WebHookEvent.last
|
||||
expect(event.payload).to eq(MultiJson.dump(ping: 'OK'))
|
||||
expect(event.status).to eq(-1)
|
||||
expect(MultiJson.load(event.response_headers)['error']).to eq('connection error')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'does not raise an error for a ping event without payload' do
|
||||
|
|
Loading…
Reference in New Issue