Common errors method added
This commit is contained in:
parent
915dac0055
commit
a065557208
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue