Skip to content

WIP: Respond with 409 when resources conflict

Matthias Käppler requested to merge github/fork/dblessing/409 into master

Created by: dblessing

** Work in progress ** Seeking feedback

Per the API docs, a 409 response should be sent when resources conflict. Right now only one part of the API actually implements this functionality (teams I believe). I believe we should make this work across the API where applicable. This is my first crack at a solution. I am seeking feedback on whether you feel this is a viable solution. If so, I will implement across the API.

Steps to reproduce: Using the API, attempt to create a project with a name or path that already exists.

Expected behavior: This should result in a 409 conflict response.

Observed behavior: A 404 not found response is received.

Errors that arise from conflicting resources are actually sent by ActiveRecord. It sends a hash that looks something like { 'name' => 'has already been taken' } or { 'path' => 'has already been taken' }. So if we check the value for 'has already been taken' we know there's a resource conflict. Then, the key of the has (like 'name') represents what attribute the error is for. Documentation for ActiveRecord validations is at http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html

Thanks for your feedback.

Merge request reports