Skip to content
This repository was archived by the owner on Oct 17, 2023. It is now read-only.

Commit cb6459e

Browse files
authored
Merge pull request #79 from jyoung488/error-message
Fix access to error message
2 parents 0ba98fe + 28888cf commit cb6459e

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

lib/hello_sign/client.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ def make_connection options
178178
def validate(response)
179179
if response.status >= 400
180180
error_class = ERRORS[response.status] || HelloSign::Error::UnknownError
181-
error = error_class.new
182-
error.response_status = response.status
183-
error.response_body = response.body
184-
error.request_uri = response.to_hash[:url].to_s
181+
error = error_class.new(response.status, response.body, response.to_hash[:url].to_s)
182+
# error.response_status = response.status
183+
# error.response_body = response.body
184+
# error.request_uri = response.to_hash[:url].to_s
185185
raise error
186186
end
187187
end

lib/hello_sign/error.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@ module HelloSign
2626
module Error
2727
# Custom error class for rescuing from all HelloSign errors.
2828
class Error < StandardError;
29-
attr_accessor :request_uri
30-
attr_accessor :response_body
31-
attr_accessor :response_status
29+
attr_accessor :request_uri, :response_body, :response_status
3230

33-
def initialize(message = nil)
34-
super(message || human_readable_message)
31+
def initialize(response_status, response_body = nil, request_uri)
32+
@request_uri = request_uri
33+
@response_body = response_body
34+
@response_status = response_status
35+
super(human_readable_message)
3536
end
3637

3738
private
3839
def human_readable_message
39-
"Server responded with code #{response_status}\n" \
40-
"Request URI: #{request_uri}\n"\
41-
"Message: #{response_body}"
40+
"Server responded with code #{@response_status}\n" \
41+
"Request URI: #{@request_uri}\n"\
42+
"Message: #{@response_body}"
4243
end
4344
end
4445

lib/hello_sign/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
#
2424

2525
module HelloSign
26-
VERSION = '3.6.1'
26+
VERSION = '3.6.2'
2727
end

spec/hello_sign/error_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
describe HelloSign::Error do
44
# another test to prove backwards compatibility
5-
describe 'custom error message' do
6-
subject { HelloSign::Error::Error.new('Foo').message }
7-
it { is_expected.to eql('Foo') }
5+
it 'raises an error with any message' do
6+
error = HelloSign::Error::Error.new(404, 'test error message', 'http://www.test.com')
7+
expect(error).to be_instance_of(HelloSign::Error::Error)
88
end
9-
end
109

10+
end

0 commit comments

Comments
 (0)