Skip to content

Commit

Permalink
Merge pull request #19 from joelbarker2011/bug/agreement-exceptions
Browse files Browse the repository at this point in the history
Raise Echosign errors for non-2xx responses
  • Loading branch information
joelbarker2011 authored Feb 11, 2019
2 parents afa3a00 + c8e8863 commit 2298ff3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Lint/UselessAssignment:
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 123
Max: 128

# Offense count: 3
# Configuration parameters: CountComments, ExcludedMethods.
Expand All @@ -60,7 +60,7 @@ Metrics/MethodLength:
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 101
Max: 105

# Offense count: 6
# Configuration parameters: CountKeywordArgs.
Expand Down
46 changes: 46 additions & 0 deletions fixtures/vcr_cassettes/create_agreement_failure.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions lib/echosign/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ def self.get(endpoint, headers)
endpoint,
headers: headers
)
response
rescue Exception => error
raise_error(error)
end

check_response(response)
end

def self.post(endpoint, body, headers, options = {})
Expand All @@ -146,20 +147,22 @@ def self.post(endpoint, body, headers, options = {})
body = body.to_json if body.is_a?(Hash)
end
response = HTTParty.post(endpoint, body: body, headers: headers)
response
rescue Exception => error
raise_error(error)
end

check_response(response)
end

def self.put(endpoint, query, headers)
begin
headers['Content-Type'] = 'application/json'
response = HTTParty.put(endpoint, body: query, headers: headers)
response
rescue Exception => error
raise_error(error)
end

check_response(response)
end

def self.add_query(url, query)
Expand All @@ -172,4 +175,9 @@ def self.raise_error(error)
"https://secure.echosign.com/public/docs/restapi/v5"
raise Failure.new message, error
end

def self.check_response(response)
raise_error(response) unless response.success?
response
end
end
6 changes: 6 additions & 0 deletions spec/lib/agreement/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
expect(agreement_id).to_not be_nil
end
end

it 'raises a specific exception on failure' do
VCR.use_cassette('create_agreement_failure', record: :once) do
expect { client.create_agreement(agreement) }.to raise_error(Echosign::Request::Failure)
end
end
end

describe '.get_agreements' do
Expand Down

0 comments on commit 2298ff3

Please sign in to comment.