andrewtennison / onside-api

the API
api.onside.me
1 stars 0 forks source link

duplicate channel name #13

Closed andrewtennison closed 12 years ago

andrewtennison commented 12 years ago

prevent duplicate channels being created. Currently 3 "test" channels. Would be good to get meaninful error when a duplicate channel is trying to be created.

symposion commented 12 years ago

I think probably the best approach to this would be to create a unique index on the relevant DB table and then look into improving the API error handling so that it can identify unique key violations and report a helpful error. Otherwise we'll have to do a redundant extra query against the DB before creating the channel which it would be better to avoid. I'll start by just putting the index on which will cause duplicate channel creation to fail with an unhelpful error, and then i'll work on improving the error.

symposion commented 12 years ago

Ok, I've fiddled with the error handling now. In the case of a violation of a unique key you will get an error response with a 500 status. Internally it will have a code of 1062 which is MySQLish for "duplicate key violation". At some point we may want to define some translation from Mysql errors to our own errors but I think this should do for the time being.