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 +4 -4
- data/lib/td/client/api.rb +37 -17
- data/lib/td/client/api_error.rb +6 -0
- data/lib/td/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ecd6b8aed80e8f53f2d1558d5d3eb7a46139bb4
|
4
|
+
data.tar.gz: cf9e411eb507cc49dbd37cce1a9dfa0b1a9b4338
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec2506706f26dce0390218f20dd350b0d0389172ad6b1adf1b047a8fff1e233c45c1cdd0ac74ae9b02cea68414b273e63d0ac2aad582a2857e42d795eea8aa35
|
7
|
+
data.tar.gz: 47094392a7112ef70587f9994a83299cac26da9a86e660ac51046efd429ae998aed4880132dcf2150aff982f0679e19298ac1eac3404c10cb85589623f1e4a36
|
data/lib/td/client/api.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
703
|
+
error['message'] = js['message'] || js['error']
|
704
|
+
error['stacktrace'] = js['stacktrace']
|
698
705
|
end
|
699
706
|
rescue JSON::ParserError
|
700
|
-
|
707
|
+
error['message'] = res.body
|
701
708
|
end
|
702
|
-
|
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
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
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
|
743
|
+
raise error_class, message
|
723
744
|
end
|
724
|
-
# TODO error
|
725
745
|
end
|
726
746
|
|
727
747
|
if ''.respond_to?(:encode)
|
data/lib/td/client/api_error.rb
CHANGED
@@ -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
|
data/lib/td/client/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|