chore: Handle exceptions on external URL calls (#1334)
This commit is contained in:
4
lib/exception_list.rb
Normal file
4
lib/exception_list.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
module ExceptionList
|
||||
URI_EXCEPTIONS = [Errno::ETIMEDOUT, Errno::ECONNREFUSED, URI::InvalidURIError, Net::OpenTimeout, SocketError].freeze
|
||||
REST_CLIENT_EXCEPTIONS = [RestClient::NotFound, RestClient::GatewayTimeout, RestClient::BadRequest, RestClient::MethodNotAllowed].freeze
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
class Webhooks::Trigger
|
||||
def self.execute(url, payload)
|
||||
RestClient.post(url, payload.to_json, { content_type: :json, accept: :json })
|
||||
rescue RestClient::NotFound, RestClient::GatewayTimeout, SocketError => e
|
||||
rescue *ExceptionList::REST_CLIENT_EXCEPTIONS, *ExceptionList::URI_EXCEPTIONS => e
|
||||
Rails.logger.info "Exception: invalid webhook url #{url} : #{e.message}"
|
||||
rescue StandardError => e
|
||||
Raven.capture_exception(e)
|
||||
|
||||
Reference in New Issue
Block a user