Added retrying

This commit is contained in:
Senad Uka
2018-08-13 15:01:28 +02:00
parent 92cadb76ed
commit 5684e58826
7 changed files with 77 additions and 14 deletions

View File

@@ -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