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,8 +5,13 @@ module Gitlab | ||
| 5 | end | 5 | end |
| 6 | 6 | ||
| 7 | def user_project | 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 | end | 15 | end |
| 11 | 16 | ||
| 12 | def authenticate! | 17 | def authenticate! |
spec/api/projects_spec.rb
| @@ -36,6 +36,12 @@ describe Gitlab::API do | @@ -36,6 +36,12 @@ describe Gitlab::API do | ||
| 36 | response.status.should == 200 | 36 | response.status.should == 200 |
| 37 | json_response['name'].should == project.name | 37 | json_response['name'].should == project.name |
| 38 | end | 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 | end | 45 | end |
| 40 | 46 | ||
| 41 | describe "GET /projects/:id/repository/branches" do | 47 | describe "GET /projects/:id/repository/branches" do |