Commit 44c62f1e authored by Drew Blessing's avatar Drew Blessing
Browse files

First crack at fixing the 409 problems

parent da98cebc
......@@ -60,6 +60,11 @@ module API
attrs
end
def handle_activerecord_errors(errors)
attribute, message = errors.first
conflict!(attribute) if message == 'has already been taken'
end
# error helpers
def forbidden!
......@@ -87,6 +92,11 @@ module API
render_api_error!('Method Not Allowed', 405)
end
def conflict!(attribute)
message = "409 " + attribute.to_s.camelize + " has already been taken"
render_api_error!(message, 409)
end
def render_api_error!(message, status)
error!({'message' => message}, status)
end
......
......@@ -85,6 +85,7 @@ module API
if @project.errors[:limit_reached].present?
error!(@project.errors[:limit_reached], 403)
end
handle_activerecord_errors(@project.errors)
not_found!
end
end
......@@ -116,6 +117,7 @@ module API
if @project.saved?
present @project, with: Entities::Project
else
handle_activerecord_errors(@project.errors)
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