Commit a0655572 authored by Alex Denisov's avatar Alex Denisov

Common errors method added

parent 915dac00
...@@ -31,22 +31,26 @@ module Gitlab ...@@ -31,22 +31,26 @@ module Gitlab
# error helpers # error helpers
def forbidden! def forbidden!
error!({'message' => '403 Forbidden'}, 403) render_api_error!('403 Forbidden', 403)
end end
def not_found!(resource = nil) def not_found!(resource = nil)
message = ["404"] message = ["404"]
message << resource if resource message << resource if resource
message << "Not Found" message << "Not Found"
error!({'message' => message.join(' ')}, 404) render_api_error!(message.join(' '), 404)
end end
def unauthorized! def unauthorized!
error!({'message' => '401 Unauthorized'}, 401) render_api_error!('401 Unauthorized', 401)
end end
def not_allowed! def not_allowed!
error!({'message' => 'method not allowed'}, 405) render_api_error!('Method Not Allowed', 405)
end
def render_api_error!(message, status)
error!({'message' => message}, status)
end end
private private
......
...@@ -85,7 +85,7 @@ describe Gitlab::API do ...@@ -85,7 +85,7 @@ describe Gitlab::API do
it "should return a 404 error if not found" do it "should return a 404 error if not found" do
get api("/projects/42", user) get api("/projects/42", user)
response.status.should == 404 response.status.should == 404
json_response['message'].should == '404 Not found' json_response['message'].should == '404 Not Found'
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment