Browse files

Raise ConflictError if 409 has occured.

This can be helpful to distinguish certain conditions. For example, when
trying to send an invitation to an already invited member.
  • Loading branch information...
1 parent adabab4 commit 4c419df4dff4c2164bc860685f03a6753a8a038d @libc committed Mar 21, 2013
Showing with 9 additions and 2 deletions.
  1. +1 −0 lib/viadeo/errors.rb
  2. +3 −1 lib/viadeo/helpers/request.rb
  3. +5 −1 spec/query_spec.rb
View
1 lib/viadeo/errors.rb
@@ -17,5 +17,6 @@ class GeneralError < ViadeoError; end
class UnavailableError < ViadeoError; end
class InformViadeoError < ViadeoError; end
class NotFoundError < ViadeoError; end
+ class ConflictError < ViadeoError; end
end
end
View
4 lib/viadeo/helpers/request.rb
@@ -74,7 +74,7 @@ def request(method, path, query, data, options)
curl.perform
end
- raise error if error
+ raise error, "An error, has occured: #{error.inspect}" if error
parse_response c
end
@@ -99,6 +99,8 @@ def parse_errors(response)
Viadeo::Errors::GeneralError
when 404
Viadeo::Errors::NotFoundError
+ when 409
+ Viadeo::Errors::ConflictError
when 500
Viadeo::Errors::InformViadeoError
when 502..503
View
6 spec/query_spec.rb
@@ -12,10 +12,14 @@
expect(obj).to respond_to(:body)
end
- it 'raises error if error actuall happens' do
+ it 'raises exception if an error actually happens' do
expect { client.get('/_raise_http_404') }.to raise_error(Viadeo::Errors::NotFoundError)
end
+ it 'raises ConflictError if 409 has occured' do
+ expect { client.get('/_raise_http_409') }.to raise_error(Viadeo::Errors::ConflictError)
+ end
+
it 'sends queries' do
obj = client.get('/test', param1: 'test')
expect(obj.body.params.param1).to eq('test')

0 comments on commit 4c419df

Please sign in to comment.