zuora_api 1.7.65g → 1.7.65i

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 844d4f29e48548bf298907952d760386687b8d9f0cc4b6f1ce26defe42d9ce30
4
- data.tar.gz: 38661f9da6c4032fe418941f1dddb1581680df7297e6eb8164deab377f82c54a
3
+ metadata.gz: 2d3a5ce233d3d4b441e52a9d4342db32d616d2bcd23e650ad0e5c09208b5904e
4
+ data.tar.gz: 5c1acb4964d32582cb84a05b0b120bde86d3d572fbeb663dff5ad2a58e228448
5
5
  SHA512:
6
- metadata.gz: 7c149b5fbb73d911e7b55dd10bf3f2d2149695a2d42866936dc43eeb1916191b54d3f666e187c08db69d84467f6e90e13750ab8f5c127b7d3610cc0484b07853
7
- data.tar.gz: ab1ecee455a237c5b2077a8e331b25d9aa2fbc82ec46ad5be9579898d1b8c4c879f8c213efe2dd494c3941f9376557af1ee5d698ec093f60729b8f198ac8b174
6
+ metadata.gz: 45f208500da4b73e03a91fd9381fb5408f2007d62f698b97c74a46c5e71616e5b312fd0beaf00a19b977aab868850b83c03e4f8910fa1f2292666e13204e8598
7
+ data.tar.gz: '06791a0a95a2031edb03efa889d35f7721f129d3e8318565e7b6a86fef6a2539b361f1ca1fe27e8470b7a43e5d6d29c463de1b0710451f539353b51e599b5903'
@@ -629,21 +629,8 @@ module ZuoraAPI
629
629
  end
630
630
  end
631
631
 
632
- if (response.code == 400 && response.headers.fetch('content-type', []).include?('text/html'))
633
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
634
- elsif response.code == 500
635
- if response.headers.fetch('content-type', []).include?('application/json')
636
- begin
637
- output_json = JSON.parse(response.body)
638
- self.raise_errors(type: :JSON, body: output_json, response: response)
639
- rescue JSON::ParserError => ex
640
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
641
- end
642
- else
643
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
644
- end
645
- end
646
-
632
+ self.errors_via_content_type(response: response, type: :xml)
633
+
647
634
  when :JSON
648
635
  case request_path
649
636
  when /^\/query\/jobs.*/ #DataQuery Paths
@@ -731,7 +718,6 @@ module ZuoraAPI
731
718
  if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(50)
732
719
  raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{messages_array.join(', ')}", response)
733
720
  end
734
-
735
721
  #Internal Server Error
736
722
  if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(60)
737
723
  if messages_array.uniq.size == 1
@@ -742,6 +728,11 @@ module ZuoraAPI
742
728
  raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("#{messages_array.join(', ')}", response)
743
729
  end
744
730
 
731
+ #Retryiable Service Error
732
+ if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(61)
733
+ raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new("#{messages_array.join(', ')}", response)
734
+ end
735
+
745
736
  #Request exceeded limit
746
737
  if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(70)
747
738
  raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new("#{messages_array.join(', ')}", response)
@@ -794,32 +785,56 @@ module ZuoraAPI
794
785
  end
795
786
  end
796
787
 
788
+ if body.class == Hash && body['message'].present?
789
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(body['message'], response) if response.code == 500
790
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body['message'], response) if ![200,201].include?(response.code)
791
+ end
792
+
793
+ self.errors_via_content_type(response: response, type: :json)
794
+
797
795
  #All other errors
798
- if response.code == 500
799
- if body.class == Hash && body['message'].present?
800
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(body['message'], response)
801
- else
802
- response_content_types = response.headers.transform_keys(&:downcase).fetch('content-type', []).first || ''
796
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new(response.body, response) if ![200,201].include?(response.code)
797
+ end
798
+ end
803
799
 
804
- if response_content_types.include?('application/xml') || response_content_types.include?('text/xml')
805
- self.raise_errors(type: :SOAP, body: Nokogiri::XML(response.body), response: response)
806
- else
807
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
808
- end
809
- end
810
- elsif ![200,201].include?(response.code)
811
- if body['message'].present?
812
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body['message'], response)
813
- else
814
- if 403 == response.code && response.body.include?("Forbidden")
815
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
816
- else
817
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new(response.body, response)
818
- end
800
+ def errors_via_content_type(response: nil, type: :xml)
801
+ response_content_types = response.headers.transform_keys(&:downcase).fetch('content-type', []).first || ""
802
+
803
+ if response_content_types.include?('application/json') && type != :json
804
+ output_json = JSON.parse(response.body)
805
+ self.raise_errors(type: :JSON, body: output_json, response: response)
806
+
807
+ elsif (response_content_types.include?('application/xml') || response_content_types.include?('text/xml')) and type != :xml
808
+ output_xml = Nokogiri::XML(response.body)
809
+ self.raise_errors(type: :SOAP, body: output_xml, response: response)
810
+
811
+ elsif response_content_types.include?('text/html')
812
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Akamai Error", response) if response.headers.fetch('server', '') == 'AkamaiGHost'
813
+
814
+ parse_body = Nokogiri::HTML(response.body)
815
+ error_title = parse_body.xpath('//h2').text
816
+ error_title = parse_body.xpath('//h1').text if error_title.blank?
817
+ error_message = parse_body.xpath('//p').text
818
+
819
+ error_message = error_title if error_message.blank?
820
+
821
+ if error_title.present?
822
+ case error_title
823
+ when /Service Unavailable/
824
+ raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new(error_message, response)
825
+ when /Client sent a bad request./, /Bad Request/, /403 Forbidden/
826
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
827
+ else
828
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(error_message, response)
819
829
  end
820
830
  end
831
+
832
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Http response body is missing", response) if response.body.blank?
821
833
  end
834
+
835
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response) if response.code == 500
822
836
  end
837
+
823
838
 
824
839
  def get_soap_error_and_message(body)
825
840
  error = body.xpath('//fns:FaultCode', 'fns' =>'http://fault.api.zuora.com/').text
@@ -885,7 +900,7 @@ module ZuoraAPI
885
900
  when /.*soapenv:Server.*/
886
901
  if /^Invalid value.*for type.*|^Id is invalid|^date string can not be less than 19 charactors$/.match(message).present?
887
902
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
888
- elsif /^Invalid white space character \(.*\) in text to output$/.match(message).present?
903
+ elsif /^Invalid white space character \(.*\) in text to output$|^Invalid null character in text to output$/.match(message).present?
889
904
  raise ZuoraAPI::Exceptions::ZuoraAPIUnkownError.new(message, response, errors, success)
890
905
  end
891
906
  raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(message, response, errors, success)
@@ -1313,7 +1328,7 @@ module ZuoraAPI
1313
1328
  end
1314
1329
  end
1315
1330
 
1316
- def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id: nil)
1331
+ def getDataSourceExport(query, extract: true, encrypted: false, zip: true, z_track_id: "")
1317
1332
  begin
1318
1333
  tries ||= 3
1319
1334
  request = Nokogiri::XML::Builder.new do |xml|
@@ -1399,6 +1414,15 @@ module ZuoraAPI
1399
1414
  raise ex
1400
1415
  end
1401
1416
 
1417
+ rescue ZuoraAPI::Exceptions::ZuoraUnexpectedError => ex
1418
+ if !(tries -= 1).zero?
1419
+ Rails.logger.info("Trace ID: #{z_track_id} UnexpectedError, will retry after 10 seconds")
1420
+ sleep 10
1421
+ retry
1422
+ else
1423
+ raise ex
1424
+ end
1425
+
1402
1426
  rescue *ZUORA_API_ERRORS => ex
1403
1427
  raise ex
1404
1428
 
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.7.65g"
2
+ VERSION = "1.7.65i"
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.65g
4
+ version: 1.7.65i
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-14 00:00:00.000000000 Z
11
+ date: 2020-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler