Skip to content

Commit 4f2760c

Browse files
committed
Simplify error checking, explicitly require Hashie::Mash
1 parent 4c40508 commit 4f2760c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lib/cortex/connection.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'faraday'
22
require 'faraday_middleware'
33
require 'addressable/uri'
4+
require 'hashie/mash'
45

56
require 'cortex/faraday_middleware/response_failures'
67

@@ -20,8 +21,6 @@ def connection
2021

2122
Faraday::Utils.default_uri_parser = Addressable::URI
2223
Faraday.new options do |conn|
23-
# Hello, temporal coupling. Order matters here.
24-
2524
## Request middleware first:
2625
conn.use ::FaradayMiddleware::OAuth2, access_token.is_a?(OAuth2::AccessToken) ? access_token.token : access_token
2726

lib/cortex/result.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize(body, headers, status)
1111
end
1212

1313
def is_error?
14-
@status >= 400 || (@contents.is_a?(Hash) && @contents.has_key?('errors'))
14+
@status >= 400 || (@contents.is_a?(Hash) && @contents.errors?)
1515
end
1616

1717
private
@@ -32,19 +32,20 @@ def parse_headers(headers)
3232
end
3333

3434
def find_errors
35+
errors = nil
3536
if is_error?
3637
if @contents.is_a?(Hash)
37-
if @contents.has_key?('errors')
38-
Array(@contents['errors'])
38+
if @contents.errors?
39+
errors = @contents.errors
3940
else
40-
Array(@contents['message'])
41+
errors = @contents.message
4142
end
4243
else
43-
Array(@contents)
44+
errors = @contents
4445
end
45-
else
46-
Array(nil)
4746
end
47+
48+
Array(errors)
4849
end
4950
end
5051
end

0 commit comments

Comments
 (0)