Skip to content
Permalink
Browse files

FIX: properly log webhook errors in UI on rescue (#7376)

  • Loading branch information...
techAPJ committed Apr 15, 2019
1 parent e92cd53 commit 594674703c20c1ef7380af3c2a3aad18f3570667
Showing with 20 additions and 3 deletions.
  1. +6 −2 app/jobs/regular/emit_web_hook_event.rb
  2. +0 −1 app/models/web_hook_event.rb
  3. +14 −0 spec/jobs/emit_web_hook_event_spec.rb
@@ -113,8 +113,12 @@ def web_hook_request(args, web_hook)
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 @@ def update_web_hook_delivery_status
else
WebHook.last_delivery_statuses[:failed]
end

web_hook.save!
end
end
@@ -78,6 +78,20 @@
)
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

1 comment on commit 5946747

@discoursebot

This comment has been minimized.

Copy link

commented on 5946747 Apr 23, 2019

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/missing-topic-web-hook-events-in-cloud-hosted-instance/115483/9

Please sign in to comment.
You can’t perform that action at this time.