lib/intercom/request.rb in intercom-2.2.1 vs lib/intercom/request.rb in intercom-2.2.2
- old
+ new
@@ -55,21 +55,27 @@
end
def execute(target_base_url=nil)
base_uri = URI.parse(target_base_url)
set_common_headers(net_http_method, base_uri)
- client(base_uri).start do |http|
- response = http.request(net_http_method)
- decoded = decode(response['content-encoding'], response.body)
- unless decoded.strip.empty?
- parsed_body = JSON.parse(decoded)
- raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body['type'] == 'error.list'
+ begin
+ client(base_uri).start do |http|
+ begin
+ response = http.request(net_http_method)
+ decoded = decode(response['content-encoding'], response.body)
+ unless decoded.strip.empty?
+ parsed_body = JSON.parse(decoded)
+ raise_application_errors_on_failure(parsed_body, response.code.to_i) if parsed_body['type'] == 'error.list'
+ end
+ raise_errors_on_failure(response)
+ parsed_body
+ rescue Timeout::Error
+ raise Intercom::ServiceUnavailableError.new('Service Unavailable [request timed out]')
+ end
end
- raise_errors_on_failure(response)
- parsed_body
+ rescue Timeout::Error
+ raise Intercom::ServiceConnectionError.new('Failed to connect to service [connection attempt timed out]')
end
- rescue Timeout::Error
- raise Intercom::ServiceUnavailableError.new('Service Unavailable')
end
def decode(content_encoding, body)
return body if (!body) || body.empty? || content_encoding != 'gzip'
Zlib::GzipReader.new(StringIO.new(body)).read