Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
From review: more robust handling of response
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-wovn committed Jul 28, 2021
1 parent 88d8f03 commit f0ba154
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/bing_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ def request_new_access_token
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @skip_ssl_verify

response = http.post(COGNITIVE_ACCESS_TOKEN_URI.path, '', headers)
if response.code == '503'
raise UnavailableException.new('503: Credentials server unavailable')
elsif response.code != '200'
raise AuthenticationException.new('Invalid credentials')
else
case response
when Net::HTTPSuccess
@access_token_expiration_time = Time.now + 480
response.body
when Net::HTTPServerError
raise UnavailableException.new("#{response.code}: Credentials server unavailable")
else
raise AuthenticationException.new('Invalid credentials')
end
end
end
Expand Down

0 comments on commit f0ba154

Please sign in to comment.