Commit cb32e0320ab538b465574bb73c7bd3d32db56d3c
1 parent
f7dd0674
Exists in
master
and in
4 other branches
return 404 if project not found
Showing
2 changed files
with
13 additions
and
2 deletions
Show diff stats
lib/api/helpers.rb
| ... | ... | @@ -5,8 +5,13 @@ module Gitlab |
| 5 | 5 | end |
| 6 | 6 | |
| 7 | 7 | def user_project |
| 8 | - @project ||= current_user.projects.find_by_id(params[:id]) || | |
| 9 | - current_user.projects.find_by_code(params[:id]) | |
| 8 | + if @project ||= current_user.projects.find_by_id(params[:id]) || | |
| 9 | + current_user.projects.find_by_code(params[:id]) | |
| 10 | + else | |
| 11 | + error!({'message' => '404 Not found'}, 404) | |
| 12 | + end | |
| 13 | + | |
| 14 | + @project | |
| 10 | 15 | end |
| 11 | 16 | |
| 12 | 17 | def authenticate! | ... | ... |
spec/api/projects_spec.rb
| ... | ... | @@ -36,6 +36,12 @@ describe Gitlab::API do |
| 36 | 36 | response.status.should == 200 |
| 37 | 37 | json_response['name'].should == project.name |
| 38 | 38 | end |
| 39 | + | |
| 40 | + it "should return a 404 error if not found" do | |
| 41 | + get "#{api_prefix}/projects/42?private_token=#{user.private_token}" | |
| 42 | + response.status.should == 404 | |
| 43 | + json_response['message'].should == '404 Not found' | |
| 44 | + end | |
| 39 | 45 | end |
| 40 | 46 | |
| 41 | 47 | describe "GET /projects/:id/repository/branches" do | ... | ... |