shipengine_ruby 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/shipengine/exceptions.rb +10 -7
- data/lib/shipengine/faraday/raise_http_exception.rb +14 -0
- data/lib/shipengine/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 623cec2a7f40bf13f4f6094812d11e4b5a929bf8ce81f67a8472493fdef3bd6d
|
4
|
+
data.tar.gz: 84cd4bf666bb3c72f89b3c0a051ba2362e41bfe07092f90c3234700877491b3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 062cc63359517d87dc76ffd2a0c6853da7eff55e6c0565b1f4452ad2029c1a51fce1f619fdccdc0472e38655550adc9ab1cc3afabea39f189456e21167abd294
|
7
|
+
data.tar.gz: d7eb59f62036b13b3b632f75c11bfd1285a6eef21a96d4aff3b31f3b4d1ae96b06baa75f962b1ff9172d25ce9ec141a39ecec0e8e93c9599ec0b35b127ff21bc
|
data/Gemfile.lock
CHANGED
@@ -8,12 +8,13 @@ module ShipEngine
|
|
8
8
|
module Exceptions
|
9
9
|
class ShipEngineError < StandardError
|
10
10
|
# message is inherited
|
11
|
-
attr_reader :source, :type, :code, :url
|
11
|
+
attr_reader :source, :type, :code, :request_id, :url
|
12
12
|
|
13
|
-
def initialize(message:, source:, type:, code:, url: nil)
|
13
|
+
def initialize(message:, source:, type:, code:, request_id: nil, url: nil)
|
14
14
|
code = ShipEngine::Errors::ErrorCode.get(code) if code.is_a?(String)
|
15
15
|
source = ShipEngine::Errors::ErrorSource.get(source) if source.is_a?(String)
|
16
16
|
super(message)
|
17
|
+
@request_id = request_id
|
17
18
|
@source = source
|
18
19
|
@type = type
|
19
20
|
@code = code
|
@@ -46,32 +47,34 @@ module ShipEngine
|
|
46
47
|
source: source,
|
47
48
|
message: message,
|
48
49
|
type: ShipEngine::Errors::ErrorType.get(:VALIDATION),
|
49
|
-
|
50
|
+
)
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
54
|
class SystemError < ShipEngineError
|
54
|
-
def initialize(message:, code:, source: nil, url: nil)
|
55
|
+
def initialize(message:, code:, source: nil, url: nil, request_id: nil)
|
55
56
|
super(
|
56
57
|
url: url,
|
57
58
|
code: code,
|
58
59
|
source: source,
|
59
60
|
message: message,
|
61
|
+
request_id: request_id,
|
60
62
|
type: ShipEngine::Errors::ErrorType.get(:SYSTEM),
|
61
|
-
|
63
|
+
)
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
67
|
class RateLimitError < SystemError
|
66
68
|
attr_reader :retries
|
67
69
|
|
68
|
-
def initialize(retries: nil, message: "You have exceeded the rate limit.", source: nil)
|
70
|
+
def initialize(retries: nil, message: "You have exceeded the rate limit.", source: nil, request_id: nil)
|
69
71
|
super(
|
70
72
|
message: message,
|
71
73
|
code: ShipEngine::Errors::ErrorCode.get(:RATE_LIMIT_EXCEEDED),
|
72
74
|
source: source,
|
75
|
+
request_id: request_id,
|
73
76
|
url: URI("https://www.shipengine.com/docs/rate-limits"),
|
74
|
-
|
77
|
+
)
|
75
78
|
@retries = retries
|
76
79
|
end
|
77
80
|
end
|
@@ -14,11 +14,13 @@ module ShipEngine
|
|
14
14
|
source: error_source(response[:body]),
|
15
15
|
type: error_type(response[:body]),
|
16
16
|
code: error_code(response[:body]),
|
17
|
+
request_id: error_request_id(response[:body]),
|
17
18
|
url: response[:url].to_s
|
18
19
|
)
|
19
20
|
elsif [429].include?(status_code)
|
20
21
|
raise ShipEngine::Exceptions::RateLimitError.new(
|
21
22
|
retries: env.request_headers["Retries"].to_i,
|
23
|
+
request_id: error_request_id(response[:body]),
|
22
24
|
source: error_source(response[:body])
|
23
25
|
)
|
24
26
|
end
|
@@ -78,6 +80,18 @@ module ShipEngine
|
|
78
80
|
body["errors"][0]["error_code"]
|
79
81
|
end
|
80
82
|
end
|
83
|
+
|
84
|
+
def error_request_id(body)
|
85
|
+
if !body.nil? && !body.empty? && body.is_a?(String)
|
86
|
+
body = JSON.parse(body)
|
87
|
+
end
|
88
|
+
|
89
|
+
if body.nil?
|
90
|
+
nil
|
91
|
+
elsif body["request_id"]
|
92
|
+
body["request_id"]
|
93
|
+
end
|
94
|
+
end
|
81
95
|
end
|
82
96
|
end
|
83
97
|
end
|
data/lib/shipengine/version.rb
CHANGED