Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add AccessDeniedError to be used when LinkedIn returns 403 status code
  • Loading branch information
Oliver Martell committed Jan 24, 2012
1 parent 83fd81d commit c884a4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/linked_in/errors.rb
Expand Up @@ -10,6 +10,7 @@ def initialize(data)

class UnauthorizedError < LinkedInError; end
class GeneralError < LinkedInError; end
class AccessDeniedError < LinkedInError; end

class UnavailableError < StandardError; end
class InformLinkedInError < StandardError; end
Expand Down
5 changes: 4 additions & 1 deletion lib/linked_in/helpers/request.rb
Expand Up @@ -44,9 +44,12 @@ def raise_errors(response)
when 401
data = Mash.from_json(response.body)
raise LinkedIn::Errors::UnauthorizedError.new(data), "(#{data.status}): #{data.message}"
when 400, 403
when 400
data = Mash.from_json(response.body)
raise LinkedIn::Errors::GeneralError.new(data), "(#{data.status}): #{data.message}"
when 403
data = Mash.from_json(response.body)
raise LinkedIn::Errors::AccessDeniedError.new(data), "(#{data.status}): #{data.message}"
when 404
raise LinkedIn::Errors::NotFoundError, "(#{response.code}): #{response.message}"
when 500
Expand Down
6 changes: 6 additions & 0 deletions spec/cases/api_spec.rb
Expand Up @@ -83,4 +83,10 @@
end
end

context "Errors" do
it "should raise AccessDeniedError when LinkedIn returns 403 status code" do
stub_request(:get, "https://api.linkedin.com/v1/people-search?first-name=Javan").to_return(:body => "{}", :status => 403)
expect{ client.search(:first_name => "Javan") }.to raise_error(LinkedIn::Errors::AccessDeniedError)
end
end
end

0 comments on commit c884a4d

Please sign in to comment.