lib/webhook_system/job.rb in webhook_system-1.0.3 vs lib/webhook_system/job.rb in webhook_system-1.0.4
- old
+ new
@@ -9,18 +9,44 @@
super(message)
@code = code
end
end
+ # Represents response for an exception we get when doing Faraday http call
+ class ErrorResponse
+ def initialize(exception)
+ @exception = exception
+ end
+
+ def status
+ 0 # no HTTP response status as we got an exception while trying to perform the request
+ end
+
+ def headers
+ {}
+ end
+
+ def body
+ [@exception.class.name, @exception.message, *@exception.backtrace].join("\n")
+ end
+ end
+
def perform(subscription, event)
self.class.post(subscription, event)
end
def self.post(subscription, event)
client = build_client
request = build_request(client, subscription, event)
- response = client.builder.build_response(client, request)
+
+ response =
+ begin
+ client.builder.build_response(client, request)
+ rescue Exception => exception # we do want to catch all exceptions
+ ErrorResponse.new(exception)
+ end
+
log_response(subscription, event, request, response)
ensure_success(response)
end
def self.ensure_success(response)
@@ -61,8 +87,7 @@
# use Faraday::Encoding middleware
faraday.response :encoding
faraday.adapter Faraday.default_adapter
end
end
-
end
end