zuora_api 1.7.44 → 1.7.45

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: 5c41d6dd1dbd9a4295b5bc51d4fce6d12f3f754d6078c2e07cf2da30da7c0968
4
- data.tar.gz: eb505fe8a19eaa9f62f0ffad34fc00b3da4a12fbc8d61a030c24aebbc4a604cd
3
+ metadata.gz: e353ae18d8ad1c0601b8bb92a40804f88781ba32be2a5196870f125869dc8eb1
4
+ data.tar.gz: f087799a2134d2c9f33e8970f5c60c0faea80e788d9549100103ffdcd0d297b9
5
5
  SHA512:
6
- metadata.gz: e8d139d75ee71fe6e3aedc9cac00744530b991e1c413f45102abdb8ac2d2eba48e462e9cf243b8a1994cba08c66efae147182d4fd05a547344c08cd88b890b23
7
- data.tar.gz: e33f029050a4b8b91f5b076b1e509d4f7a5cb2edb8751b17cc639ae0a0ee4c5034250fa280b63e514c043cc4e9caecfc511fdf51ce7a5a3da2ecde48531279b2
6
+ metadata.gz: 4f948a1d0f0b04cbd14dcaff50f7c699c3195c8710ecb70a22802f4e4298bd6769b674ad2302e279fce1b2894ffe1b7ca8b7c6522ccc6ddc31735a3d27342ac0
7
+ data.tar.gz: 6d10f65bb4f49332d96d296c9167748e79129ac61a9f086ac1834a7671c32ecd7c089e1c38bf7678ee4211a6721e0f5c1e68a5199bfdcba37582beae1e9add3f
@@ -51,6 +51,8 @@ module ZuoraAPI
51
51
  @message = "Adjustment cannot be created for invoice with a zero balance."
52
52
  when /The balance of all the invoice items and tax items is 0. No write-off is needed for the invoice .*./
53
53
  @message = "The balance of all the invoice items and tax items is 0. No write-off is needed for the invoice."
54
+ when /Json input does not match schema. Error(s): string ".*" is too long .*/
55
+ @message = "Json input does not match schema. Error(s): String is too long."
54
56
  else
55
57
  @message = message
56
58
  end
@@ -16,7 +16,8 @@ module ZuoraAPI
16
16
  Errno::ECONNREFUSED,
17
17
  SocketError,
18
18
  Errno::EHOSTUNREACH,
19
- Errno::EADDRNOTAVAIL
19
+ Errno::EADDRNOTAVAIL,
20
+ Errno::ETIMEDOUT,
20
21
  ].freeze
21
22
 
22
23
  CONNECTION_READ_EXCEPTIONS = [
@@ -385,7 +386,7 @@ module ZuoraAPI
385
386
  end
386
387
 
387
388
  def rest_domain
388
- return URI(self.rest_endpoint).host
389
+ return URI(self.rest_endpoint).host
389
390
  end
390
391
 
391
392
  def fileURL(url="")
@@ -429,13 +430,26 @@ module ZuoraAPI
429
430
  else
430
431
  raise ZuoraAPI::Exceptions::ZuoraAPIAuthenticationTypeError.new("Unknown Login, does not support Authentication of Type: #{auth_type}")
431
432
  end
432
-
433
+
433
434
  raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(self.current_error) if self.status != 'Active'
434
435
  return prefix ? "Bearer #{self.bearer_token}" : self.bearer_token.to_s
435
436
  end
436
437
  end
437
438
 
438
- def soap_call(ns1: 'ns1', ns2: 'ns2', batch_size: nil, single_transaction: false, debug: false, zuora_track_id: nil, errors: [ZuoraAPI::Exceptions::ZuoraAPISessionError].concat(ZUORA_API_ERRORS), z_session: true, timeout_retry: false, timeout: 120,**keyword_args)
439
+ def soap_call(
440
+ ns1: 'ns1',
441
+ ns2: 'ns2',
442
+ batch_size: nil,
443
+ single_transaction: false,
444
+ debug: false,
445
+ zuora_track_id: nil,
446
+ errors: [ZuoraAPI::Exceptions::ZuoraAPISessionError].concat(ZUORA_API_ERRORS),
447
+ soft_errors: [],
448
+ z_session: true,
449
+ timeout_retry: false,
450
+ timeout: 120,
451
+ output_exception_messages: true,
452
+ **keyword_args)
439
453
  tries ||= 2
440
454
  xml = Nokogiri::XML::Builder.new do |xml|
441
455
  xml['SOAP-ENV'].Envelope('xmlns:SOAP-ENV' => "http://schemas.xmlsoap.org/soap/envelope/",
@@ -480,7 +494,7 @@ module ZuoraAPI
480
494
  output_xml = Nokogiri::XML(response.body)
481
495
  Rails.logger.debug("Response SOAP XML: #{output_xml.to_xml(:save_with => XML_SAVE_OPTIONS).strip}") if debug
482
496
 
483
- raise_errors(type: :SOAP, body: output_xml, response: response)
497
+ raise_errors(type: :SOAP, body: output_xml, response: response, soft_errors: soft_errors)
484
498
  rescue ZuoraAPI::Exceptions::ZuoraAPISessionError => ex
485
499
  if !tries.zero? && z_session
486
500
  tries -= 1
@@ -509,7 +523,13 @@ module ZuoraAPI
509
523
  end
510
524
  rescue *CONNECTION_EXCEPTIONS => ex
511
525
  if tries.zero?
512
- Rails.logger.info("SOAP Call - #{ex.class} Timed out will retry after 5 seconds")
526
+ if output_exception_messages
527
+ if Rails.logger.class.to_s == "Ougai::Logger"
528
+ Rails.logger.error("SOAP Call - Timed out will retry after #{self.timeout_sleep} seconds", ex)
529
+ else
530
+ Rails.logger.error("SOAP Call - #{ex.class} Timed out will retry after #{self.timeout_sleep} seconds")
531
+ end
532
+ end
513
533
  raise ex
514
534
  end
515
535
 
@@ -518,7 +538,13 @@ module ZuoraAPI
518
538
  retry
519
539
  rescue *CONNECTION_READ_EXCEPTIONS => ex
520
540
  if tries.zero?
521
- Rails.logger.info("SOAP Call - #{ex.class} Timed out will retry after 5 seconds")
541
+ if output_exception_messages
542
+ if Rails.logger.class.to_s == "Ougai::Logger"
543
+ Rails.logger.error("SOAP Call - Timed out will retry after #{self.timeout_sleep} seconds", ex)
544
+ else
545
+ Rails.logger.error("SOAP Call - #{ex.class} Timed out will retry after #{self.timeout_sleep} seconds")
546
+ end
547
+ end
522
548
  raise ex
523
549
  end
524
550
 
@@ -530,7 +556,13 @@ module ZuoraAPI
530
556
  sleep(self.timeout_sleep)
531
557
  retry
532
558
  else
533
- Rails.logger.info("SOAP Call - #{ex.class} Timed out will retry after 5 seconds")
559
+ if output_exception_messages
560
+ if Rails.logger.class.to_s == "Ougai::Logger"
561
+ Rails.logger.error("SOAP Call - Timed out will retry after #{self.timeout_sleep} seconds", ex)
562
+ else
563
+ Rails.logger.error("SOAP Call - #{ex.class} Timed out will retry after #{self.timeout_sleep} seconds")
564
+ end
565
+ end
534
566
  raise ex
535
567
  end
536
568
  rescue => ex
@@ -539,7 +571,7 @@ module ZuoraAPI
539
571
  return output_xml, input_xml, response
540
572
  end
541
573
 
542
- def raise_errors(type: :SOAP, body: nil, response: nil)
574
+ def raise_errors(type: :SOAP, body: nil, response: nil, soft_errors: [])
543
575
  if [502,503].include?(response.code)
544
576
  raise ZuoraAPI::Exceptions::ZuoraAPIConnectionTimeout.new("Received #{response.code} from #{response.request.uri}", response)
545
577
  end
@@ -556,21 +588,45 @@ module ZuoraAPI
556
588
  when :SOAP
557
589
  error, success, message = get_soap_error_and_message(body)
558
590
 
591
+ if body.xpath('//ns1:queryResponse', 'ns1' => 'http://api.zuora.com/').present? &&
592
+ body.xpath(
593
+ '//ns1:records[@xsi:type="ns2:Export"]',
594
+ 'ns1' => 'http://api.zuora.com/', 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance'
595
+ ).present?
596
+ if body.xpath('//ns1:size', 'ns1' => 'http://api.zuora.com/').text.to_i < 1 && soft_errors.include?(:export_size_0)
597
+ error = 'UNEXPECTED_ERROR'
598
+ message = 'No export found.'
599
+ end
600
+
601
+ result = body.xpath('//ns2:Status', 'ns2' => 'http://object.api.zuora.com/').text
602
+ if result == 'Failed'
603
+ reason = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
604
+ if reason.present?
605
+ message = body.xpath('//ns2:StatusReason', 'ns2' => 'http://object.api.zuora.com/').text
606
+ error = message.include?('Unexpected error') ? 'UNEXPECTED_ERROR' : 'FAIL_ERROR'
607
+ else
608
+ error = 'UNEXPECTED_ERROR'
609
+ message = 'Export failed due to unknown reason. Consult api logs.'
610
+ end
611
+ end
612
+ end
613
+
559
614
  #By default response if not passed in for SOAP as all SOAP is 200
560
615
  if error.present?
561
616
  if error.class == String
562
- raise_errors_helper(error, message, response)
617
+ raise_errors_helper(error: error, message: message, response: response)
563
618
  elsif error.class == Array
564
619
  if error.uniq.size == 1
565
620
  err, msg = error[0].split('::')
566
- raise_errors_helper(err, msg, response, error, success)
621
+ raise_errors_helper(error: err, message: msg, response: response, errors: error, success: success)
567
622
  else
568
623
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new(error.group_by {|v| v}.map {|k,v| "(#{v.size}x) - #{k == "::" ? 'UNKNOWN::No error provided' : k}"}.join(', '), response, error, success)
569
624
  end
570
625
  end
571
- elsif response.code == 500 ||
572
- (response.code == 400 && response.headers.fetch('content-type', []).include?('text/html'))
573
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new('Zuora API Internal Server Error', response)
626
+ end
627
+
628
+ if response.code == 500 || (response.code == 400 && response.headers.fetch('content-type', []).include?('text/html'))
629
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response)
574
630
  end
575
631
 
576
632
  when :JSON
@@ -636,7 +692,7 @@ module ZuoraAPI
636
692
  #Locking contention
637
693
  if codes_array.map{|code| code.to_s.slice(6,7).to_i}.include?(50)
638
694
  raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("#{messages_array.join(', ')}", response)
639
- end
695
+ end
640
696
 
641
697
  #All Errors catch
642
698
  if codes_array.size > 0
@@ -645,22 +701,7 @@ module ZuoraAPI
645
701
 
646
702
  #Zuora REST Query Errors
647
703
  if body["faultcode"].present?
648
- case body["faultcode"]
649
- when "fns:MALFORMED_QUERY"
650
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body["faultstring"], response)
651
- when "fns:REQUEST_EXCEEDED_LIMIT"
652
- raise ZuoraAPI::Exceptions::ZuoraAPIRequestLimit.new(body["faultstring"], response)
653
- when "fns:LOCK_COMPETITION"
654
- raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new(body["faultstring"], response)
655
- when "INVALID_SESSION"
656
- raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(body["faultstring"], response)
657
- when /fns:INVALID_TYPE/
658
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new(body["faultstring"], response)
659
- when /.*soapenv:Server.*/
660
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(body["faultstring"], response)
661
- else
662
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Z:#{body["faultcode"]}::#{body["faultstring"]}", response)
663
- end
704
+ raise_errors_helper(error: body["faultcode"], message: body["faultstring"], response: response)
664
705
  end
665
706
 
666
707
  if body["Errors"].present? || body["errors"].present?
@@ -686,7 +727,7 @@ module ZuoraAPI
686
727
  raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new("Retry Lock Competition", response)
687
728
  elsif error_messages.first.include?("data integrity violation")
688
729
  raise ZuoraAPI::Exceptions::ZuoraDataIntegrity.new("Data Integrity Violation", response)
689
- end
730
+ end
690
731
  end
691
732
  end
692
733
 
@@ -746,7 +787,7 @@ module ZuoraAPI
746
787
  return error, success, message
747
788
  end
748
789
 
749
- def raise_errors_helper(error, message, response, errors = [], success = [])
790
+ def raise_errors_helper(error: nil, message: nil, response: nil, errors: [], success: [])
750
791
  case error
751
792
  when /.*INVALID_SESSION/
752
793
  raise ZuoraAPI::Exceptions::ZuoraAPISessionError.new(message, response, errors, success)
@@ -759,40 +800,31 @@ module ZuoraAPI
759
800
  raise ZuoraAPI::Exceptions::ZuoraAPILockCompetition.new(message, response, errors, success)
760
801
  elsif message.include?("org.hibernate.exception.ConstraintViolationException")
761
802
  raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(message, response, errors, success)
762
- else
763
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
764
803
  end
804
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
765
805
  when /.*TEMPORARY_ERROR/
766
806
  raise ZuoraAPI::Exceptions::ZuoraAPITemporaryError.new(message, response, errors, success)
767
807
  when /.*INVALID_VALUE/
768
808
  if message.include?("data integrity violation")
769
809
  raise ZuoraAPI::Exceptions::ZuoraDataIntegrity.new("Data Integrity Violation", response, errors), success
770
- else
771
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
772
810
  end
811
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
773
812
  when /.*UNKNOWN_ERROR/
774
813
  if /payment\/refund|Credit Balance Adjustment|Payment Gateway|ARSettlement permission/.match(message).nil?
775
814
  raise ZuoraAPI::Exceptions::ZuoraAPIUnkownError.new(message, response, errors, success)
776
- else
777
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
778
815
  end
816
+ raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
779
817
  when /INVALID_ID/, /MAX_RECORDS_EXCEEDED/, /INVALID_FIELD/, /MALFORMED_QUERY/, /NO_PERMISSION/, /PDF_QUERY_ERROR/, /MISSING_REQUIRED_VALUE/, /INVALID_TYPE/, /TRANSACTION_FAILED/, /API_DISABLED/, /CANNOT_DELETE/, /ACCOUNTING_PERIOD_CLOSED/
780
818
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
819
+ when /.*UNEXPECTED_ERROR/
820
+ raise ZuoraAPI::Exceptions::ZuoraUnexpectedError.new(message.to_s, response, errors, success)
781
821
  when /.*soapenv:Server.*/
782
822
  if /Invalid value.*for type|Id is invalid/.match(message).present?
783
823
  raise ZuoraAPI::Exceptions::ZuoraAPIError.new(message, response, errors, success)
784
824
  end
785
825
  raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(message, response, errors, success)
786
- end
787
-
788
- if response.code == 500
789
- if message.present?
790
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Z:#{error}::#{message}", response, errors, success)
791
- else
792
- raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new(response.body, response, errors, success)
793
- end
794
- else
795
- raise ZuoraAPI::Exceptions::ZuoraAPIError.new("Z:#{error}::#{message}", response, errors, success) if error.present?
826
+ else
827
+ raise ZuoraAPI::Exceptions::ZuoraAPIInternalServerError.new("Z:#{error}::#{message}", response, errors, success)
796
828
  end
797
829
  end
798
830
 
@@ -875,7 +907,13 @@ module ZuoraAPI
875
907
  end
876
908
  rescue *(CONNECTION_EXCEPTIONS + CONNECTION_READ_EXCEPTIONS) => ex
877
909
  if tries.zero?
878
- Rails.logger.info("Describe - #{ex.class} Timed out will retry after 5 seconds")
910
+ if log_errors
911
+ if Rails.logger.class.to_s == "Ougai::Logger"
912
+ Rails.logger.error("Describe - Timed out will retry after #{self.timeout_sleep} seconds", ex)
913
+ else
914
+ Rails.logger.error("Describe - #{ex.class} Timed out will retry after #{self.timeout_sleep} seconds")
915
+ end
916
+ end
879
917
  raise ex
880
918
  end
881
919
 
@@ -911,6 +949,7 @@ module ZuoraAPI
911
949
  timeout: 120,
912
950
  multipart: false,
913
951
  stream_body: false,
952
+ output_exception_messages: true,
914
953
  **keyword_args,
915
954
  &block
916
955
  )
@@ -988,7 +1027,13 @@ module ZuoraAPI
988
1027
  raise ex
989
1028
  rescue *CONNECTION_EXCEPTIONS => ex
990
1029
  if tries.zero?
991
- Rails.logger.info("Rest Call - #{ex.class} Timed out will retry after 5 seconds")
1030
+ if output_exception_messages
1031
+ if Rails.logger.class.to_s == "Ougai::Logger"
1032
+ Rails.logger.error("Rest Call - Timed out will retry after #{self.timeout_sleep} seconds", ex)
1033
+ else
1034
+ Rails.logger.error("Rest Call - #{ex.class} Timed out will retry after #{self.timeout_sleep} seconds")
1035
+ end
1036
+ end
992
1037
  raise ex
993
1038
  end
994
1039
 
@@ -997,7 +1042,13 @@ module ZuoraAPI
997
1042
  retry
998
1043
  rescue *CONNECTION_READ_EXCEPTIONS => ex
999
1044
  if tries.zero?
1000
- Rails.logger.info("Rest Call - #{ex.class} Timed out will retry after 5 seconds")
1045
+ if output_exception_messages
1046
+ if Rails.logger.class.to_s == "Ougai::Logger"
1047
+ Rails.logger.error("Rest Call - Timed out will retry after #{self.timeout_sleep} seconds", ex)
1048
+ else
1049
+ Rails.logger.error("Rest Call - #{ex.class} Timed out will retry after #{self.timeout_sleep} seconds")
1050
+ end
1051
+ end
1001
1052
  raise ex
1002
1053
  end
1003
1054
 
@@ -1009,7 +1060,13 @@ module ZuoraAPI
1009
1060
  sleep(self.timeout_sleep)
1010
1061
  retry
1011
1062
  else
1012
- Rails.logger.info("Rest Call - #{ex.class} Timed out will retry after 5 seconds")
1063
+ if output_exception_messages
1064
+ if Rails.logger.class.to_s == "Ougai::Logger"
1065
+ Rails.logger.error("Rest Call - Timed out will retry after #{self.timeout_sleep} seconds", ex)
1066
+ else
1067
+ Rails.logger.error("Rest Call - #{ex.class} Timed out will retry after #{self.timeout_sleep} seconds")
1068
+ end
1069
+ end
1013
1070
  raise ex
1014
1071
  end
1015
1072
  rescue => ex
@@ -1181,8 +1238,8 @@ module ZuoraAPI
1181
1238
  raise ZuoraAPI::Exceptions::FileDownloadError.new("File Download Failed #{response.class}")
1182
1239
  end
1183
1240
  end
1184
-
1185
- rescue => ex
1241
+
1242
+ rescue => ex
1186
1243
  sleep(5)
1187
1244
  if (retry_count -= 1) >= 0
1188
1245
  retry
@@ -1,3 +1,3 @@
1
1
  module ZuoraAPI
2
- VERSION = "1.7.44"
2
+ VERSION = "1.7.45"
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.44
4
+ version: 1.7.45
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-02-13 00:00:00.000000000 Z
11
+ date: 2020-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler