retry webhooks on non 200 status

pull/217/head
Pete Matsyburka 2 years ago
parent d1d26b5424
commit f8b24ebfce

@ -3,6 +3,8 @@
class SendFormCompletedWebhookRequestJob < ApplicationJob
USER_AGENT = 'DocuSeal.co Webhook'
NotSuccessStatus = Class.new(StandardError)
def perform(submitter)
config = Accounts.load_webhook_configs(submitter.submission.account)
@ -12,7 +14,7 @@ class SendFormCompletedWebhookRequestJob < ApplicationJob
ActiveStorage::Current.url_options = Docuseal.default_url_options
Faraday.post(config.value,
resp = Faraday.post(config.value,
{
event_type: 'form.completed',
timestamp: Time.current,
@ -20,5 +22,9 @@ class SendFormCompletedWebhookRequestJob < ApplicationJob
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)
if resp.status.to_i >= 400 && (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
raise NotSuccessStatus, resp.status.to_s
end
end
end

@ -3,6 +3,8 @@
class SendFormStartedWebhookRequestJob < ApplicationJob
USER_AGENT = 'DocuSeal.co Webhook'
NotSuccessStatus = Class.new(StandardError)
def perform(submitter)
config = Accounts.load_webhook_configs(submitter.submission.account)
@ -10,7 +12,7 @@ class SendFormStartedWebhookRequestJob < ApplicationJob
ActiveStorage::Current.url_options = Docuseal.default_url_options
Faraday.post(config.value,
resp = Faraday.post(config.value,
{
event_type: 'form.started',
timestamp: Time.current,
@ -18,5 +20,9 @@ class SendFormStartedWebhookRequestJob < ApplicationJob
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)
if resp.status.to_i >= 400 && (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
raise NotSuccessStatus, resp.status.to_s
end
end
end

@ -3,6 +3,8 @@
class SendFormViewedWebhookRequestJob < ApplicationJob
USER_AGENT = 'DocuSeal.co Webhook'
NotSuccessStatus = Class.new(StandardError)
def perform(submitter)
config = Accounts.load_webhook_configs(submitter.submission.account)
@ -10,7 +12,7 @@ class SendFormViewedWebhookRequestJob < ApplicationJob
ActiveStorage::Current.url_options = Docuseal.default_url_options
Faraday.post(config.value,
resp = Faraday.post(config.value,
{
event_type: 'form.viewed',
timestamp: Time.current,
@ -18,5 +20,9 @@ class SendFormViewedWebhookRequestJob < ApplicationJob
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)
if resp.status.to_i >= 400 && (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
raise NotSuccessStatus, resp.status.to_s
end
end
end

Loading…
Cancel
Save