Added retrying
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
require 'rest-client'
|
||||
require 'retries'
|
||||
require 'json'
|
||||
require_relative '../exceptions'
|
||||
|
||||
module Pruning
|
||||
module Repos
|
||||
@@ -11,8 +12,19 @@ module Pruning
|
||||
end
|
||||
|
||||
def get(name)
|
||||
resp = @client.get(url(name))
|
||||
JSON(resp.body)
|
||||
with_retries(max_tries: 3, rescue: [Pruning::Exceptions::ServerErrorOnOrigin]) do
|
||||
begin
|
||||
resp = @client.get(url(name))
|
||||
rescue RestClient::ExceptionWithResponse => e
|
||||
if e.response.code != 404
|
||||
raise Pruning::Exceptions::ServerErrorOnOrigin
|
||||
else
|
||||
raise Pruning::Exceptions::OriginCannotFindTheResource
|
||||
end
|
||||
end
|
||||
return JSON(resp.body)
|
||||
end
|
||||
raise Pruning::Exceptions::UnexpectedError
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user