summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
diff options
context:
space:
mode:
authorAlex Denisov <1101.debian@gmail.com>2012-09-10 10:41:46 +0300
committerAlex Denisov <1101.debian@gmail.com>2012-09-10 10:41:46 +0300
commit915dac0055cd801c080ebcd37749f4fc6d2d12c4 (patch)
tree1de457b9c3d95d98051432d4686f89f981429ccb /lib/api/helpers.rb
parenta839cb427cc158330297fd89fbf40321d41349a4 (diff)
downloadgitlab-ce-915dac0055cd801c080ebcd37749f4fc6d2d12c4.tar.gz
Error throwing moved to api_helper
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb27
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index c0ba874790a..3a385f1582a 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -8,7 +8,7 @@ module Gitlab
if @project ||= current_user.projects.find_by_id(params[:id]) ||
current_user.projects.find_by_code(params[:id])
else
- error!({'message' => '404 Not found'}, 404)
+ not_found!
end
@project
@@ -19,15 +19,36 @@ module Gitlab
end
def authenticate!
- error!({'message' => '401 Unauthorized'}, 401) unless current_user
+ unauthorized! unless current_user
end
def authorize! action, subject
unless abilities.allowed?(current_user, action, subject)
- error!({'message' => '403 Forbidden'}, 403)
+ forbidden!
end
end
+ # error helpers
+
+ def forbidden!
+ error!({'message' => '403 Forbidden'}, 403)
+ end
+
+ def not_found!(resource = nil)
+ message = ["404"]
+ message << resource if resource
+ message << "Not Found"
+ error!({'message' => message.join(' ')}, 404)
+ end
+
+ def unauthorized!
+ error!({'message' => '401 Unauthorized'}, 401)
+ end
+
+ def not_allowed!
+ error!({'message' => 'method not allowed'}, 405)
+ end
+
private
def abilities