Skip to content

Commit 4aecef6

Browse files
author
Scott Martin
committed
Handle 401 errors from Diffbot.
1 parent 08ef493 commit 4aecef6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/diffbot/api_client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ def request(method, path, data = {}, headers = {})
186186
response = connection.send(method.to_sym, path, data) do |request|
187187
request.headers.update(headers)
188188
end
189+
190+
code = response.env[:body][:errorCode]
191+
raise(Diffbot::APIClient::Unauthorized.new(code)) if code == 401
192+
189193
response.env
190194
rescue Faraday::Error::TimeoutError, Timeout::Error => error
191195
raise(Diffbot::APIClient::RequestTimeout.new(error))

lib/diffbot/api_client/error.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@ def initialize(exception = $ERROR_INFO)
2424
class RequestTimeout < Error
2525
end
2626

27+
# Raised when Diffbot returns errorCode 401.
28+
class Unauthorized < Error
29+
end
2730
end
2831
end

0 commit comments

Comments
 (0)