Merge pull request #9573 from demarches-simplifiees/add-sentry-to-webhook-call
remonte les erreurs dans Sentry lorsqu'un appel webhook est en erreur
This commit is contained in:
commit
7b9f44ec42
2 changed files with 31 additions and 1 deletions
|
@ -10,7 +10,15 @@ class WebHookJob < ApplicationJob
|
|||
state: state,
|
||||
updated_at: updated_at
|
||||
}
|
||||
|
||||
procedure = Procedure.find(procedure_id)
|
||||
Typhoeus.post(procedure.web_hook_url, body: body, timeout: TIMEOUT)
|
||||
|
||||
response = Typhoeus.post(procedure.web_hook_url, body: body, timeout: TIMEOUT)
|
||||
|
||||
if !response.success?
|
||||
Sentry.set_tags(procedure: procedure_id, dossier: dossier_id)
|
||||
Sentry.set_extras(web_hook_url: procedure.web_hook_url)
|
||||
Sentry.capture_message("Webhook error: #{response.status} // Response: #{response.body}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
22
spec/jobs/web_hook_job_spec.rb
Normal file
22
spec/jobs/web_hook_job_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
describe WebHookJob, type: :job do
|
||||
describe 'perform' do
|
||||
let(:procedure) { create(:procedure, web_hook_url:) }
|
||||
let(:dossier) { create(:dossier, procedure:) }
|
||||
let(:web_hook_url) { "https://domaine.fr/callback_url" }
|
||||
let(:job) { WebHookJob.new(procedure.id, dossier.id, dossier.state, dossier.updated_at) }
|
||||
|
||||
context 'with success on webhook' do
|
||||
it 'calls webhook' do
|
||||
stub_request(:post, web_hook_url).to_return(status: 200, body: "success")
|
||||
expect { job.perform_now }.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'with error on webhook' do
|
||||
it 'raises' do
|
||||
stub_request(:post, web_hook_url).to_return(status: 500, body: "error")
|
||||
expect { job.perform_now }.to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue