Skip to content

Commit

Permalink
Raise NotFound instead of RestClient::ResourceNotFound
Browse files Browse the repository at this point in the history
When attempting to load a repo that does not exist or is not visible to the
logged-in user.
  • Loading branch information
jwilger committed Jun 26, 2011
1 parent 3084f81 commit 47873d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/github_v3_api/repos_api.rb
Expand Up @@ -40,6 +40,8 @@ def list
def get(user, repo_name)
org_data = @connection.get("/repos/#{user}/#{repo_name}")
GitHubV3API::Repo.new_with_all_data(self, org_data)
rescue RestClient::ResourceNotFound
raise NotFound, "The repository #{user}/#{repo_name} does not exist or is not visible to the user."
end
end
end
8 changes: 8 additions & 0 deletions spec/repos_api_spec.rb
Expand Up @@ -21,5 +21,13 @@
GitHubV3API::Repo.should_receive(:new_with_all_data).with(api, :repo_hash).and_return(:repo)
api.get('octocat', 'hello-world').should == :repo
end

it 'raises GitHubV3API::NotFound instead of a RestClient::ResourceNotFound' do
connection = mock(GitHubV3API)
connection.should_receive(:get) \
.and_raise(RestClient::ResourceNotFound)
api = GitHubV3API::ReposAPI.new(connection)
lambda { api.get('octocat', 'hello-world') }.should raise_error(GitHubV3API::NotFound)
end
end
end

0 comments on commit 47873d6

Please sign in to comment.