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
|
duration: ((Time.zone.now - now) * 1000).to_i
|
||||||
)
|
)
|
||||||
rescue => e
|
rescue => e
|
||||||
web_hook_event.update!(headers: MultiJson.dump(headers))
|
web_hook_event.update!(
|
||||||
Rails.logger.error("Webhook event failed: #{e}")
|
headers: MultiJson.dump(headers),
|
||||||
|
status: -1,
|
||||||
|
response_headers: MultiJson.dump(error: e),
|
||||||
|
duration: ((Time.zone.now - now) * 1000).to_i
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
MessageBus.publish("/web_hook_events/#{web_hook.id}", {
|
MessageBus.publish("/web_hook_events/#{web_hook.id}", {
|
||||||
|
|
|
@ -19,7 +19,6 @@ class WebHookEvent < ActiveRecord::Base
|
||||||
else
|
else
|
||||||
WebHook.last_delivery_statuses[:failed]
|
WebHook.last_delivery_statuses[:failed]
|
||||||
end
|
end
|
||||||
|
|
||||||
web_hook.save!
|
web_hook.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -78,6 +78,20 @@ describe Jobs::EmitWebHookEvent do
|
||||||
)
|
)
|
||||||
end.to change { Jobs::EmitWebHookEvent.jobs.size }.by(0)
|
end.to change { Jobs::EmitWebHookEvent.jobs.size }.by(0)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
it 'does not raise an error for a ping event without payload' do
|
it 'does not raise an error for a ping event without payload' do
|
||||||
|
|
Loading…
Reference in New Issue