geoloqi 0.9.10 → 0.9.11
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/geoloqi/error.rb +5 -4
- data/lib/geoloqi/session.rb +1 -1
- data/lib/geoloqi/version.rb +1 -1
- data/spec/geoloqi_spec.rb +11 -3
- metadata +1 -1
data/lib/geoloqi/error.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
module Geoloqi
|
2
2
|
class ApiError < StandardError
|
3
|
-
attr_reader :type
|
4
|
-
|
5
|
-
|
3
|
+
attr_reader :status, :type, :reason
|
4
|
+
def initialize(status, type, reason=nil)
|
5
|
+
@status = status
|
6
6
|
@type = type
|
7
7
|
@reason = reason
|
8
8
|
message = type
|
9
9
|
message += " - #{reason}" if reason
|
10
|
+
message += " (#{status})"
|
10
11
|
super message
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
15
|
class Error < StandardError; end
|
15
16
|
class ArgumentError < ArgumentError; end
|
16
|
-
end
|
17
|
+
end
|
data/lib/geoloqi/session.rb
CHANGED
@@ -55,7 +55,7 @@ module Geoloqi
|
|
55
55
|
end
|
56
56
|
|
57
57
|
hash = JSON.parse response.body
|
58
|
-
raise ApiError.new(hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error']
|
58
|
+
raise ApiError.new(response.status, hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error']
|
59
59
|
rescue Geoloqi::ApiError
|
60
60
|
raise Error.new('Unable to procure fresh access token from API on second attempt') if retry_attempt > 0
|
61
61
|
if hash['error'] == 'expired_token'
|
data/lib/geoloqi/version.rb
CHANGED
data/spec/geoloqi_spec.rb
CHANGED
@@ -28,10 +28,11 @@ end
|
|
28
28
|
|
29
29
|
describe Geoloqi::ApiError do
|
30
30
|
it 'throws exception properly and allows drill-down of message' do
|
31
|
-
error = Geoloqi::ApiError.new 'not_enough_cats', 'not enough cats to complete this request'
|
31
|
+
error = Geoloqi::ApiError.new 405, 'not_enough_cats', 'not enough cats to complete this request'
|
32
|
+
expect { error.status == 405 }
|
32
33
|
expect { error.type == 'not_enough_cats' }
|
33
34
|
expect { error.reason == 'not enough cats to complete this request' }
|
34
|
-
expect { error.message == "#{error.type} - #{error.reason}" }
|
35
|
+
expect { error.message == "#{error.type} - #{error.reason} (405)" }
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
@@ -182,7 +183,14 @@ describe Geoloqi::Session do
|
|
182
183
|
end
|
183
184
|
|
184
185
|
it 'fails with an exception' do
|
185
|
-
|
186
|
+
begin
|
187
|
+
@session.get 'message/send'
|
188
|
+
rescue Exception => e
|
189
|
+
expect { e.class == Geoloqi::ApiError }
|
190
|
+
expect { e.status == 401 }
|
191
|
+
expect { e.type == 'invalid_token' }
|
192
|
+
expect { e.message == 'invalid_token (401)' }
|
193
|
+
end
|
186
194
|
end
|
187
195
|
end
|
188
196
|
|