zuora_api 1.7.65f → 1.7.66c

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7d938d4f3650b7d013c75dd8331ff79d18892c3608f4a37e2709e5053203d4e
4
- data.tar.gz: 97d6019971a7d1fe835e4dad6c58aa3768851dbd2193708811927baaafa864b8
3
+ metadata.gz: 461c544727a1c87da9074597e00bca16191713827f05faef4f93bd0bb871c0ce
4
+ data.tar.gz: 6214b8eea0900f6db43a670be948d52dcc769233eeccf9202619f803c9a1275b
5
5
  SHA512:
6
- metadata.gz: f6926089bf23d4762906a3f292f42b8e66a7b6ec7c55e0fab3e38b78785f8fdb0e18e669e98227b13d0dc3e467476606e0634297ab1ca4535e8f09fa95faff9a
7
- data.tar.gz: 6803980d193339f1eba377d6591716660cca17a21fb9b873f112d6308883314336fb308d97fd222d2009e2772a24c595dc4751428d502a900ccd3cc3f8e05e12
6
+ metadata.gz: 8631be8f69c675f66274d3b902ea61a1d06a0748b2fe8d626986784b6d7430d369180b4e6573f4272bbef1b5e200d306dab08897882987dd89a4512b7058968f
7
+ data.tar.gz: 2e201fe035b941a6a499df4e336e31dc287fca7b6bdb779ad0cea5ecfac5dbf3a8fc482efebaeb67ea75ed3a23018958a1db090ccccc996685c27aab13383ca8
@@ -177,14 +177,15 @@ module ZuoraAPI
177
177
  end
178
178
 
179
179
  class ZuoraAPITemporaryError < Error
180
- attr_reader :code, :response
180
+ attr_reader :code, :response, :errors
181
181
  attr_writer :default_message
182
182
 
183
- def initialize(message = nil,response=nil, errors = [], successes = [], *args)
183
+ def initialize(message = nil, response = nil, errors = [], successes = [], *args)
184
184
  @code = response.class.to_s == "HTTParty::Response" ? response.code : nil
185
185
  @message = parse_message(message)
186
186
  @response = response
187
187
  @default_message = "There is a temporary error with zuora system."
188
+ @errors = errors
188
189
  end
189
190
 
190
191
  def to_s
@@ -39,8 +39,8 @@ module ZuoraAPI
39
39
 
40
40
  ZUORA_SERVER_ERRORS = [
41
41
  ZuoraAPI::Exceptions::ZuoraAPIInternalServerError,
42
- ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout,
43
- ZuoraAPI::Exceptions::ZuoraAPIReadTimeout,
42
+ ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout,
43
+ ZuoraAPI::Exceptions::ZuoraAPIReadTimeout,
44
44
  ZuoraAPI::Exceptions::ZuoraUnexpectedError
45
45
  ].freeze
46
46
 
@@ -500,20 +500,18 @@ module ZuoraAPI
500
500
  end
501
501
 
502
502
  retry
503
- else
504
- if errors.include?(ex.class)
505
- raise ex
506
- else
507
- return output_xml, input_xml, response
508
- end
509
503
  end
504
+
505
+ raise ex if errors.include?(ex.class)
506
+
507
+ return output_xml, input_xml, response
508
+
510
509
  rescue *ZUORA_API_ERRORS => ex
511
- if errors.include?(ex.class)
512
- raise ex
513
- else
514
- response = ex.response unless response
515
- return output_xml, input_xml, response
516
- end
510
+ raise ex if errors.include?(ex.class)
511
+
512
+ response = ex.response unless response
513
+ return output_xml, input_xml, response
514
+
517
515
  rescue *CONNECTION_EXCEPTIONS => ex
518
516
  if tries.zero?
519
517
  if output_exception_messages
@@ -557,24 +555,33 @@ module ZuoraAPI
557
555
  end
558
556
 
559
557
  def raise_errors(type: :SOAP, body: nil, response: nil)
560
- request = response.request
561
- match_string = "#{request.http_method.to_s.split("Net::HTTP::").last.upcase}::#{response.code}::#{request.path.path}"
558
+ request_uri, request_path, match_string = "", "", ""
559
+ if response.class.to_s == "HTTP::Message"
560
+ request_uri = response.http_header.request_uri.to_s
561
+ request_path = response.http_header.request_uri.path
562
+ match_string = "#{response.http_header.request_method}::#{response.code}::#{request_uri}"
563
+ else
564
+ request = response.request
565
+ request_uri = response.request.uri
566
+ request_path = request.path.path
567
+ match_string = "#{request.http_method.to_s.split("Net::HTTP::").last.upcase}::#{response.code}::#{request_path}"
568
+ end
562
569
 
563
570
  if [502,503].include?(response.code)
564
- raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{response.request.uri}", response)
571
+ raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{request_uri}", response)
565
572
  end
566
573
 
567
574
  # Check failure response code
568
575
  case response.code
569
576
  when 504
570
- raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from #{response.request.uri}", response)
577
+ raise ZuoraAPI::Exceptions::ZuoraAPIReadTimeout.new("Received 504 from #{request_uri}", response)
571
578
  when 429
572
579
  raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("The total number of concurrent requests has exceeded the limit allowed by the system. Please resubmit your request later.", response)
573
580
  when 401
574
581
 
575
582
  else
576
583
  if body.class == Hash
577
- case response.request.path.path
584
+ case request_path
578
585
  when /^\/v1\/connections$/
579
586
  response_headers = response.headers.to_h
580
587
  raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Missing cookies for authentication call", response) if response_headers['set-cookie'].blank?
@@ -598,7 +605,7 @@ module ZuoraAPI
598
605
  reason = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
599
606
  if reason.present?
600
607
  message = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
601
- error = message.match(/^[\w\d]{16}\: (Unexpected error.|No HTTP Response|Socket Timeout)/).present? ? 'UNEXPECTED_ERROR' : 'FATAL_ERROR'
608
+ error = message.match(/^[\w\d]{16}\: (Unexpected error.|No HTTP Response|Socket Timeout|There is an internal error, please try again later)/).present? ? 'UNEXPECTED_ERROR' : 'FATAL_ERROR'
602
609
  else
603
610
  error = 'FATAL_ERROR'
604
611
  message = 'Export failed due to unknown reason. Consult api logs.'
@@ -620,23 +627,10 @@ module ZuoraAPI
620
627
  end
621
628
  end
622
629
 
623
- if (response.code == 400 && response.headers.fetch('content-type', []).include?('text/html'))
624
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
625
- elsif response.code == 500
626
- if response.headers.fetch('content-type', []).include?('application/json')
627
- begin
628
- output_json = JSON.parse(response.body)
629
- self.raise_errors(type: :JSON, body: output_json, response: response)
630
- rescue JSON::ParserError => ex
631
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
632
- end
633
- else
634
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
635
- end
636
- end
637
-
630
+ self.errors_via_content_type(response: response, type: :xml)
631
+
638
632
  when :JSON
639
- case request.path.path
633
+ case request_path
640
634
  when /^\/query\/jobs.*/ #DataQuery Paths
641
635
  return if body.class != Hash
642
636
  case match_string
@@ -662,6 +656,10 @@ module ZuoraAPI
662
656
  when /^GET::400::\/api\/rest\/v1\/reports\/(reportlabels\/)?([a-zA-Z0-9\-_]+)\/report-details$/ # Get report, capture of the id is present if needed in future error responses.
663
657
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new(reporting_message, response) if reporting_message.present?
664
658
  end
659
+ when /\/objects\/batch\//
660
+ if body['code'].present? && /61$/.match(body['code'].to_s).present? # if last 2 digits of code are 61
661
+ raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new(body['message'], nil, body['details'])
662
+ end
665
663
  end
666
664
 
667
665
  body = body.dig("results").present? ? body["results"] : body if body.class == Hash
@@ -722,7 +720,6 @@ module ZuoraAPI
722
720
  if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(50)
723
721
  raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{messages_array.join(', ')}", response)
724
722
  end
725
-
726
723
  #Internal Server Error
727
724
  if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(60)
728
725
  if messages_array.uniq.size == 1
@@ -733,6 +730,11 @@ module ZuoraAPI
733
730
  raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("#{messages_array.join(', ')}", response)
734
731
  end
735
732
 
733
+ #Retryiable Service Error
734
+ if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(61)
735
+ raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new("#{messages_array.join(', ')}", response)
736
+ end
737
+
736
738
  #Request exceeded limit
737
739
  if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(70)
738
740
  raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}", response)
@@ -785,32 +787,56 @@ module ZuoraAPI
785
787
  end
786
788
  end
787
789
 
790
+ if body.class == Hash && body['message'].present?
791
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(body['message'], response) if response.code == 500
792
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body['message'], response) if ![200,201].include?(response.code)
793
+ end
794
+
795
+ self.errors_via_content_type(response: response, type: :json)
796
+
788
797
  #All other errors
789
- if response.code == 500
790
- if body.class == Hash && body['message'].present?
791
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(body['message'], response)
792
- else
793
- response_content_types = response.headers.transform_keys(&:downcase).fetch('content-type', []).first || ''
798
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new(response.body, response) if ![200,201].include?(response.code)
799
+ end
800
+ end
794
801
 
795
- if response_content_types.include?('application/xml') || response_content_types.include?('text/xml')
796
- self.raise_errors(type: :SOAP, body: Nokogiri::XML(response.body), response: response)
797
- else
798
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
799
- end
800
- end
801
- elsif ![200,201].include?(response.code)
802
- if body['message'].present?
803
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body['message'], response)
804
- else
805
- if 403 == response.code && response.body.include?("Forbidden")
806
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
807
- else
808
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new(response.body, response)
809
- end
802
+ def errors_via_content_type(response: nil, type: :xml)
803
+ response_content_types = response.headers.transform_keys(&:downcase).fetch('content-type', []).first || ""
804
+
805
+ if response_content_types.include?('application/json') && type != :json
806
+ output_json = JSON.parse(response.body)
807
+ self.raise_errors(type: :JSON, body: output_json, response: response)
808
+
809
+ elsif (response_content_types.include?('application/xml') || response_content_types.include?('text/xml')) and type != :xml
810
+ output_xml = Nokogiri::XML(response.body)
811
+ self.raise_errors(type: :SOAP, body: output_xml, response: response)
812
+
813
+ elsif response_content_types.include?('text/html')
814
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Akamai Error", response) if response.headers.fetch('server', '') == 'AkamaiGHost'
815
+
816
+ parse_body = Nokogiri::HTML(response.body)
817
+ error_title = parse_body.xpath('//h2').text
818
+ error_title = parse_body.xpath('//h1').text if error_title.blank?
819
+ error_message = parse_body.xpath('//p').text
820
+
821
+ error_message = error_title if error_message.blank?
822
+
823
+ if error_title.present?
824
+ case error_title
825
+ when /Service Unavailable/
826
+ raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new(error_message, response)
827
+ when /Client sent a bad request./, /Bad Request/, /403 Forbidden/
828
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
829
+ else
830
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
810
831
  end
811
832
  end
833
+
834
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Http response body is missing", response) if response.body.blank?
812
835
  end
836
+
837
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response) if response.code == 500
813
838
  end
839
+
814
840
 
815
841
  def get_soap_error_and_message(body)
816
842
  error = body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text
@@ -874,9 +900,9 @@ module ZuoraAPI
874
900
  when /.*UNEXPECTED_ERROR/
875
901
  raise ZuoraAPI::Exceptions::ZuoraUnexpectedError.new(message, response, errors, success)
876
902
  when /.*soapenv:Server.*/
877
- if /^Invalid value.*for type.*|^Id is invalid/.match(message).present?
903
+ if /^Invalid value.*for type.*|^Id is invalid|^date string can not be less than 19 charactors$/.match(message).present?
878
904
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
879
- elsif /^Invalid white space character \(.*\) in text to output$/.match(message).present?
905
+ elsif /^Invalid white space character \(.*\) in text to output$|^Invalid null character in text to output$/.match(message).present?
880
906
  raise ZuoraAPI::Exceptions::ZuoraAPIUnkownError.new(message, response, errors, success)
881
907
  end
882
908
  raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(message, response, errors, success)
@@ -1056,10 +1082,10 @@ module ZuoraAPI
1056
1082
  if self.class.to_s == 'ZuoraAPI::Oauth' && ex.message.include?("Authentication type is not supported by this Login")
1057
1083
  session_type = :bearer
1058
1084
  retry
1059
- else
1060
- Rails.logger.debug("Rest Call - Session Bad Auth type")
1061
- raise ex
1062
1085
  end
1086
+ Rails.logger.debug("Rest Call - Session Bad Auth type")
1087
+ raise ex
1088
+
1063
1089
  rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
1064
1090
  if !tries.zero? && z_session
1065
1091
  tries -= 1
@@ -1072,20 +1098,17 @@ module ZuoraAPI
1072
1098
  end
1073
1099
 
1074
1100
  retry
1075
- else
1076
- if errors.include?(ex.class)
1077
- raise ex
1078
- else
1079
- return [output_json, response]
1080
- end
1081
1101
  end
1102
+
1103
+ raise ex if errors.include?(ex.class)
1104
+ return [output_json, response]
1105
+
1082
1106
  rescue *ZUORA_API_ERRORS => ex
1083
- if errors.include?(ex.class)
1084
- raise ex
1085
- else
1086
- response = ex.response unless response
1087
- return [output_json, response]
1088
- end
1107
+ raise ex if errors.include?(ex.class)
1108
+
1109
+ response = ex.response unless response
1110
+ return [output_json, response]
1111
+
1089
1112
  rescue ZuoraAPI::Exceptions::BadEntityError => ex
1090
1113
  raise ex
1091
1114
  rescue *CONNECTION_EXCEPTIONS => ex
@@ -1304,75 +1327,122 @@ module ZuoraAPI
1304
1327
  end
1305
1328
  end
1306
1329
 
1307
- def getDataSourceExport(query, extract: true, encrypted: false, zip: true)
1308
- request = Nokogiri::XML::Builder.new do |xml|
1309
- xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:ns2' => "http://object.api.zuora.com/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:ns1' => "http://api.zuora.com/") do
1310
- xml['SOAP-ENV'].Header do
1311
- xml['ns1'].SessionHeader do
1312
- xml['ns1'].session self.get_session(prefix: false, auth_type: :basic)
1330
+ def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id: "")
1331
+ begin
1332
+ tries ||= 3
1333
+ request = Nokogiri::XML::Builder.new do |xml|
1334
+ xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:ns2' => "http://object.api.zuora.com/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:ns1' => "http://api.zuora.com/") do
1335
+ xml['SOAP-ENV'].Header do
1336
+ xml['ns1'].SessionHeader do
1337
+ xml['ns1'].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: z_track_id)
1338
+ end
1313
1339
  end
1314
- end
1315
- xml['SOAP-ENV'].Body do
1316
- xml['ns1'].create do
1317
- xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
1318
- xml['ns2'].Format 'csv'
1319
- xml['ns2'].Zip zip
1320
- xml['ns2'].Name 'googman'
1321
- xml['ns2'].Query query
1322
- xml['ns2'].Encrypted encrypted
1340
+ xml['SOAP-ENV'].Body do
1341
+ xml['ns1'].create do
1342
+ xml['ns1'].zObjects('xsi:type' => "ns2:Export") do
1343
+ xml['ns2'].Format 'csv'
1344
+ xml['ns2'].Zip zip
1345
+ xml['ns2'].Name 'googman'
1346
+ xml['ns2'].Query query
1347
+ xml['ns2'].Encrypted encrypted
1348
+ end
1323
1349
  end
1324
1350
  end
1325
1351
  end
1326
1352
  end
1327
- end
1328
1353
 
1329
- response_query = HTTParty.post(self.url, body: request.to_xml(:save_with => XML_SAVE_OPTIONS).strip, headers: {'Content-Type' => "application/json; charset=utf-8"}, :timeout => 120)
1354
+ response_query = HTTParty.post(self.url, body: request.to_xml(:save_with => XML_SAVE_OPTIONS).strip, headers: {'Content-Type' => "application/json; charset=utf-8", "Z-Track-Id" => z_track_id}, :timeout => 120)
1355
+
1356
+ output_xml = Nokogiri::XML(response_query.body)
1357
+ raise_errors(type: :SOAP, body: output_xml, response: response_query) if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
1330
1358
 
1331
- output_xml = Nokogiri::XML(response_query.body)
1332
- raise 'Export Creation Unsuccessful : ' + output_xml.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
1333
- id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
1359
+ # raise "Export Creation Unsuccessful : #{response_query.code}: #{response_query.parsed_response}" if output_xml.xpath('//ns1:Success', 'ns1' =>'http://api.zuora.com/').text != "true"
1360
+
1361
+ id = output_xml.xpath('//ns1:Id', 'ns1' =>'http://api.zuora.com/').text
1334
1362
 
1335
- confirmRequest = Nokogiri::XML::Builder.new do |xml|
1336
- xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:ns2' => "http://object.api.zuora.com/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:ns1' => "http://api.zuora.com/") do
1337
- xml['SOAP-ENV'].Header do
1338
- xml['ns1'].SessionHeader do
1339
- xml['ns1'].session self.get_session(prefix: false, auth_type: :basic)
1363
+ confirmRequest = Nokogiri::XML::Builder.new do |xml|
1364
+ xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:ns2' => "http://object.api.zuora.com/", 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xmlns:ns1' => "http://api.zuora.com/") do
1365
+ xml['SOAP-ENV'].Header do
1366
+ xml['ns1'].SessionHeader do
1367
+ xml['ns1'].session self.get_session(prefix: false, auth_type: :basic, zuora_track_id: z_track_id)
1368
+ end
1340
1369
  end
1341
- end
1342
- xml['SOAP-ENV'].Body do
1343
- xml['ns1'].query do
1344
- xml['ns1'].queryString "SELECT Id, CreatedById, CreatedDate, Encrypted, FileId, Format, Name, Query, Size, Status, StatusReason, UpdatedById, UpdatedDate, Zip From Export where Id = '#{id}'"
1370
+ xml['SOAP-ENV'].Body do
1371
+ xml['ns1'].query do
1372
+ xml['ns1'].queryString "SELECT Id, CreatedById, CreatedDate, Encrypted, FileId, Format, Name, Query, Size, Status, StatusReason, UpdatedById, UpdatedDate, Zip From Export where Id = '#{id}'"
1373
+ end
1345
1374
  end
1346
1375
  end
1347
1376
  end
1348
- end
1349
- result = 'Waiting'
1377
+ result = 'Waiting'
1350
1378
 
1351
- while result != "Completed"
1352
- sleep 3
1353
- response_query = HTTParty.post(self.url, body: confirmRequest.to_xml(:save_with => XML_SAVE_OPTIONS).strip, headers: {'Content-Type' => "application/json; charset=utf-8"}, :timeout => 120)
1379
+ while result != "Completed"
1380
+ sleep 3
1381
+ response_query = HTTParty.post(self.url, body: confirmRequest.to_xml(:save_with => XML_SAVE_OPTIONS).strip, headers: {'Content-Type' => "application/json; charset=utf-8", "Z-Track-Id" => z_track_id}, :timeout => 120)
1354
1382
 
1355
- output_xml = Nokogiri::XML(response_query.body)
1356
- result = output_xml.xpath('//ns2:Status', 'ns2' =>'http://object.api.zuora.com/').text
1357
- status_code = response_query.code if response_query
1358
- raise "Export Creation Unsuccessful : #{output_xml.xpath('//ns1:Message', 'ns1' =>'http://api.zuora.com/').text}" if result.blank? || result == "Failed"
1359
- end
1383
+ output_xml = Nokogiri::XML(response_query.body)
1384
+ result = output_xml.xpath('//ns2:Status', 'ns2' =>'http://object.api.zuora.com/').text
1385
+ status_code = response_query.code if response_query
1360
1386
 
1361
- file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
1362
- export_file = get_file(:url => self.fileURL(file_id))
1363
- export_file_path = export_file.path
1364
- Rails.logger.debug("=====> Export path #{export_file.path}")
1365
-
1366
- if extract && zip
1367
- require "zip"
1368
- new_path = export_file_path.partition('.zip').first
1369
- zipped = Zip::File.open(export_file_path)
1370
- file_handle = zipped.entries.first
1371
- file_handle.extract(new_path)
1372
- File.delete(export_file_path)
1373
- return new_path
1374
- else
1375
- return export_file_path
1387
+ raise_errors(type: :SOAP, body: output_xml, response: response_query) if result.blank? || result == "Failed"
1388
+ # raise "Export Creation Unsuccessful : #{response_query.code}: #{response_query.parsed_response}" if result.blank? || result == "Failed"
1389
+ end
1390
+
1391
+ file_id = output_xml.xpath('//ns2:FileId', 'ns2' =>'http://object.api.zuora.com/').text
1392
+ export_file = get_file(:url => self.fileURL(file_id))
1393
+ export_file_path = export_file.path
1394
+ Rails.logger.debug("=====> Export path #{export_file.path}")
1395
+
1396
+ if extract && zip
1397
+ require "zip"
1398
+ new_path = export_file_path.partition('.zip').first
1399
+ zipped = Zip::File.open(export_file_path)
1400
+ file_handle = zipped.entries.first
1401
+ file_handle.extract(new_path)
1402
+ File.delete(export_file_path)
1403
+ return new_path
1404
+ else
1405
+ return export_file_path
1406
+ end
1407
+ rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
1408
+ if !(tries -= 1).zero?
1409
+ Rails.logger.info("Export call failed - Trace ID: #{z_track_id}")
1410
+ self.new_session
1411
+ retry
1412
+ else
1413
+ raise ex
1414
+ end
1415
+
1416
+ rescue ZuoraAPI::Exceptions::ZuoraUnexpectedError => ex
1417
+ if !(tries -= 1).zero?
1418
+ Rails.logger.info("Trace ID: #{z_track_id} UnexpectedError, will retry after 10 seconds")
1419
+ sleep 10
1420
+ retry
1421
+ else
1422
+ raise ex
1423
+ end
1424
+
1425
+ rescue *ZUORA_API_ERRORS => ex
1426
+ raise ex
1427
+
1428
+ rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
1429
+ if !(tries -= 1).zero?
1430
+ Rails.logger.info("Trace ID: #{z_track_id} Timed out will retry after 5 seconds")
1431
+ sleep 5
1432
+ retry
1433
+ else
1434
+ raise ex
1435
+ end
1436
+
1437
+ rescue Errno::ECONNRESET => ex
1438
+ if !(tries -= 1).zero? && ex.message.include?('SSL_connect')
1439
+ retry
1440
+ else
1441
+ raise ex
1442
+ end
1443
+
1444
+ rescue ZuoraAPI::Exceptions::BadEntityError => ex
1445
+ raise ex
1376
1446
  end
1377
1447
  end
1378
1448
 
@@ -37,7 +37,13 @@ module ZuoraAPI
37
37
  begin
38
38
  self.current_session = response.headers.to_h['set-cookie'][0].split(';')[0].split('=',2)[1].gsub('%3D', '=')
39
39
  rescue NoMethodError => ex
40
- Rails.logger.fatal("Failure Parsing Cookie Headers", response.headers.to_s)
40
+ Rails.logger.fatal("Failure Parsing Cookie Headers", {
41
+ response: {
42
+ status: response.code,
43
+ params: response.body.to_s,
44
+ headers: response.headers.to_s,
45
+ }
46
+ })
41
47
  raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Failure Parsing Cookie Headers")
42
48
  end
43
49
  rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
@@ -46,34 +52,26 @@ module ZuoraAPI
46
52
  Rails.logger.debug {"Session Invalid"}
47
53
  self.new_session(auth_type: :bearer)
48
54
  retry
49
- else
50
- if errors.include?(ex.class)
51
- raise ex
52
- else
53
- return [output_json, response]
54
- end
55
- end
56
- rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
57
- if errors.include?(ex.class)
58
- raise ex
59
- else
60
- return [output_json, response]
61
55
  end
56
+ raise ex
57
+
58
+ rescue ZuoraAPI::Exceptions::ZuoraAPIError, ZuoraAPI::Exceptions::ZuoraAPIRequestLimit, ZuoraAPI::Exceptions::ZuoraAPILockCompetition => ex
59
+ raise ex
60
+
62
61
  rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
63
62
  if !tries.zero?
64
63
  tries -= 1
65
64
  sleep(self.timeout_sleep)
66
65
  retry
66
+ end
67
+ if Rails.logger.class.to_s == "Ougai::Logger"
68
+ Rails.logger.error("OAuthLogin - Timed out", ex)
67
69
  else
68
- if Rails.logger.class.to_s == "Ougai::Logger"
69
- Rails.logger.error("OAuthLogin - Timed out", ex)
70
- else
71
- Rails.logger.error("OAuthLogin - #{ex.class} Timed out")
72
- end
73
- self.current_error = "Request timed out. Try again"
74
- self.status = 'Timeout'
75
- return self.status
70
+ Rails.logger.error("OAuthLogin - #{ex.class} Timed out")
76
71
  end
72
+ self.current_error = "Request timed out. Try again"
73
+ self.status = 'Timeout'
74
+ return self.status
77
75
  end
78
76
 
79
77
  def get_bearer_token(zuora_track_id: nil)
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.7.65f"
2
+ VERSION = "1.7.66c"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.65f
4
+ version: 1.7.66c
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zuora Strategic Solutions Group
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-12 00:00:00.000000000 Z
11
+ date: 2020-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler