td-client 0.8.74 → 0.8.75

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
  SHA1:
3
- metadata.gz: 1e7c8e5d2d7a083101d43af5aac57da1832683b2
4
- data.tar.gz: 95dd9d3cd7e6ee9a743e774dbabcc0c78981d9e8
3
+ metadata.gz: 1ecd6b8aed80e8f53f2d1558d5d3eb7a46139bb4
4
+ data.tar.gz: cf9e411eb507cc49dbd37cce1a9dfa0b1a9b4338
5
5
  SHA512:
6
- metadata.gz: a031a8d19b916bb07ca496612388349fb922577f15dbaddbd8b54c78f054d5ebd4bb894ea877f13a5bdd8e4166fd30b69c46918cb989510b035deac3631ee2ac
7
- data.tar.gz: d528d13d61573d7f89b50a8b2a6cb05656705f4a39cad03ae59aa2b10cd49f95a08b318f847c1c8d6e685ad97dc0d3ccfb1a66b99c43642bad0f98e008b8826f
6
+ metadata.gz: ec2506706f26dce0390218f20dd350b0d0389172ad6b1adf1b047a8fff1e233c45c1cdd0ac74ae9b02cea68414b273e63d0ac2aad582a2857e42d795eea8aa35
7
+ data.tar.gz: 47094392a7112ef70587f9994a83299cac26da9a86e660ac51046efd429ae998aed4880132dcf2150aff982f0679e19298ac1eac3404c10cb85589623f1e4a36
@@ -685,21 +685,29 @@ private
685
685
  # @param [response] res
686
686
  # @return [String]
687
687
  def get_error(res)
688
+ parse_error_response(res)['message']
689
+ end
690
+
691
+ def parse_error_response(res)
692
+ error = {}
693
+
688
694
  begin
689
695
  js = JSON.load(res.body)
690
696
  if js.nil?
691
- error_msg = if res.respond_to?(:message)
697
+ error['message'] = if res.respond_to?(:message)
692
698
  res.message # Net::HTTP
693
699
  else
694
700
  res.reason # HttpClient
695
701
  end
696
702
  else
697
- error_msg = js['message'] || js['error']
703
+ error['message'] = js['message'] || js['error']
704
+ error['stacktrace'] = js['stacktrace']
698
705
  end
699
706
  rescue JSON::ParserError
700
- error_msg = res.body
707
+ error['message'] = res.body
701
708
  end
702
- error_msg
709
+
710
+ error
703
711
  end
704
712
 
705
713
  # @param [String] msg
@@ -707,21 +715,33 @@ private
707
715
  # @param [Class] klass
708
716
  def raise_error(msg, res, klass=nil)
709
717
  status_code = res.code.to_s
710
- error_msg = get_error(res)
711
- if klass
712
- raise klass, "#{status_code}: #{msg}: #{res.body}"
713
- elsif status_code == "404"
714
- raise NotFoundError, "#{msg}: #{res.body}"
715
- elsif status_code == "409"
716
- raise AlreadyExistsError, "#{msg}: #{res.body}"
717
- elsif status_code == "401"
718
- raise AuthError, "#{msg}: #{res.body}"
719
- elsif status_code == "403"
720
- raise ForbiddenError, "#{msg}: #{res.body}"
718
+ error = parse_error_response(res)
719
+ message = "#{msg}: #{error['message']}"
720
+
721
+ error_class = if klass
722
+ message = "#{status_code}: #{message}"
723
+ klass
724
+ else
725
+ case status_code
726
+ when "404"
727
+ NotFoundError
728
+ when "409"
729
+ AlreadyExistsError
730
+ when "401"
731
+ AuthError
732
+ when "403"
733
+ ForbiddenError
734
+ else
735
+ message = "#{status_code}: #{message}"
736
+ APIError
737
+ end
738
+ end
739
+
740
+ if error_class.method_defined?(:api_backtrace)
741
+ raise error_class.new(message, error['stacktrace'])
721
742
  else
722
- raise APIError, "#{status_code}: #{msg}: #{res.body}"
743
+ raise error_class, message
723
744
  end
724
- # TODO error
725
745
  end
726
746
 
727
747
  if ''.respond_to?(:encode)
@@ -5,6 +5,12 @@ end
5
5
 
6
6
  # Generic API error
7
7
  class APIError < StandardError
8
+ attr_reader :api_backtrace
9
+
10
+ def initialize(error_message = nil, api_backtrace = nil)
11
+ super(error_message)
12
+ @api_backtrace = api_backtrace == '' ? nil : api_backtrace
13
+ end
8
14
  end
9
15
 
10
16
  # 401 API errors
@@ -1,5 +1,5 @@
1
1
  module TreasureData
2
2
  class Client
3
- VERSION = '0.8.74'
3
+ VERSION = '0.8.75'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: td-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.74
4
+ version: 0.8.75
5
5
  platform: ruby
6
6
  authors:
7
7
  - Treasure Data, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack