Commit a0655572 authored by Alex Denisov's avatar Alex Denisov

Common errors method added

parent 915dac00
......@@ -31,22 +31,26 @@ module Gitlab
# error helpers
def forbidden!
error!({'message' => '403 Forbidden'}, 403)
render_api_error!('403 Forbidden', 403)
end
def not_found!(resource = nil)
message = ["404"]
message << resource if resource
message << "Not Found"
error!({'message' => message.join(' ')}, 404)
render_api_error!(message.join(' '), 404)
end
def unauthorized!
error!({'message' => '401 Unauthorized'}, 401)
render_api_error!('401 Unauthorized', 401)
end
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
private
......
......@@ -85,7 +85,7 @@ describe Gitlab::API do
it "should return a 404 error if not found" do
get api("/projects/42", user)
response.status.should == 404
json_response['message'].should == '404 Not found'
json_response['message'].should == '404 Not Found'
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