Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/yelp/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def initialize(msg='One or more parameters were invalid', error=nil)
unless error.nil?
@text = error['text']
@field = error['field']
msg = msg + ': ' + @field
msg += ": #{@field}"
msg += ". Description: #{error['description']}" if error.has_key?('description')
end
super(msg,error)
end
Expand Down
21 changes: 13 additions & 8 deletions spec/yelp/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,21 @@
}.to raise_error(Yelp::Error::InvalidParameter)
end

it 'should expose the field parameter' do
begin
it 'should expose the field parameter' do
expect {
Yelp::Error.check_for_error(bad_response)
rescue Yelp::Error::InvalidParameter => e
# verifies that StandardError message attribute is available
expect(e.message).to eq('One or more parameters are invalid in request: oauth_token')
# verifies that we can get access to the specific field that was invalid
expect(e.field).to eq('oauth_token')
end
}.to raise_error ('One or more parameters are invalid in request: oauth_token')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missing: expect { }.to raise_error(ErrorClass, error_message)


end

context 'when the API returns the error description' do
let(:response_body) { '{"error": {"text": "One or more parameters are invalid in request", "id": "INVALID_PARAMETER", "field": "limit", "description": "Limit maximum is 20"}}' }

it 'should expose more details about the invalid parameter' do
expect {
Yelp::Error.check_for_error(bad_response)
}.to raise_error ('One or more parameters are invalid in request: limit. Description: Limit maximum is 20')
end
end
end
end