Bad API URL's return HTTP 500; propose returning HTTP 404 instead
Created by: cyvasse
I was trying out the Gitlab API. The docs clearly state that the URL is /api/v3/projects, but for some reason I tried /api/projects instead. This returned HTTP 500 due to a NoMethodError in project.rb. I eventually figured out that it should be /api/v3/projects.
I would have figured out my mistake faster if the result had been HTTP 404 instead. Since HTTP 404 is a more appropriate error code for an incorrect URL, I'd like to propose the fix mentioned in the issue title: Non-existing URL's under /api should return HTTP 404.
The command that gives the 500 is:
wget 'http://localhost/api/projects?private_token=abcdefgh12345678xxxx'
In /home/gitlab/gitlab/log/production.log the following information:
Started GET "/api/projects?private_token=abcdefgh12345678xxxx" for 127.0.0.1 at 2012-12-27 07:30:31 +0000
Processing by ProjectsController#show as */*
Parameters: {"private_token"=>"abcdefgh12345678xxxx", "id"=>"api/projects"}
Completed 500 Internal Server Error in 65ms
NoMethodError (undefined method `id' for nil:NilClass):
app/models/project.rb:104:in `find_with_namespace'
app/controllers/application_controller.rb:69:in `project'
Details about my setup: I just did my first Gitlab install from 4-0-stable. I tried the above command before uploading any repos, and again after pushing one repo; both gave the same results. I installed everything to the recommended paths and usernames. The most recent commit in the gitlab server's tree at /home/gitlab/gitlab is c68540e9. I haven't tried other API URL's. I used my actual private token as displayed in the /profile/account URL when I ran the above command, but I replaced it with abcdefgh... in this description to keep my private token private.