Common errors method added
This commit is contained in:
parent
915dac0055
commit
a065557208
2 changed files with 9 additions and 5 deletions
|
@ -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
|
||||||
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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue