lib/webhook_system/job.rb in webhook_system-2.1.4 vs lib/webhook_system/job.rb in webhook_system-2.1.5
- old
+ new
@@ -3,13 +3,14 @@
# This is the ActiveJob in charge of actually sending each event
class Job < ActiveJob::Base
# Exception class around non 200 responses
class RequestFailed < RuntimeError
- def initialize(message, code)
+ def initialize(message, code, error_message=nil)
super(message)
@code = code
+ @error_message = error_message
end
end
# Represents response for an exception we get when doing Faraday http call
class ErrorResponse
@@ -44,15 +45,17 @@
rescue RuntimeError => exception
ErrorResponse.new(exception)
end
log_response(subscription, event, request, response)
- ensure_success(response.status, :POST, subscription.url)
+ ensure_success(response, :POST, subscription.url)
end
- def self.ensure_success(status, http_method, url)
+ def self.ensure_success(response, http_method, url)
+ status = response.status
unless (200..299).cover? status
- raise RequestFailed.new("#{http_method} request to #{url} failed with code: #{status}", status)
+ text = "#{http_method} request to #{url} failed with code: #{status} and error #{response.body}"
+ raise RequestFailed.new(text, status, response.body)
end
end
def self.build_request(client, subscription, event)
payload, headers = Encoder.encode(subscription.secret, event, format: format_for_subscription(subscription))