Close #483. Return 409 if a database already exist

pull/483/merge
Edward Muller 2014-04-29 20:44:41 -07:00 committed by John Shahid
parent 85e507242c
commit d054713e63
3 changed files with 13 additions and 1 deletions

View File

@ -321,6 +321,8 @@ func errorToStatusCode(err error) int {
return libhttp.StatusUnauthorized // HTTP 401 return libhttp.StatusUnauthorized // HTTP 401
case AuthorizationError: case AuthorizationError:
return libhttp.StatusForbidden // HTTP 403 return libhttp.StatusForbidden // HTTP 403
case DatabaseExistsError:
return libhttp.StatusConflict // HTTP 409
default: default:
return libhttp.StatusBadRequest // HTTP 400 return libhttp.StatusBadRequest // HTTP 400
} }

View File

@ -269,7 +269,7 @@ func (self *ClusterConfiguration) CreateDatabase(name string, replicationFactor
defer self.createDatabaseLock.Unlock() defer self.createDatabaseLock.Unlock()
if _, ok := self.DatabaseReplicationFactors[name]; ok { if _, ok := self.DatabaseReplicationFactors[name]; ok {
return fmt.Errorf("database %s exists", name) return common.NewDatabaseExistsError(name)
} }
self.DatabaseReplicationFactors[name] = replicationFactor self.DatabaseReplicationFactors[name] = replicationFactor
return nil return nil

View File

@ -42,3 +42,13 @@ func (self AuthorizationError) Error() string {
func NewAuthorizationError(formatStr string, args ...interface{}) AuthorizationError { func NewAuthorizationError(formatStr string, args ...interface{}) AuthorizationError {
return AuthorizationError(fmt.Sprintf(formatStr, args...)) return AuthorizationError(fmt.Sprintf(formatStr, args...))
} }
type DatabaseExistsError string
func (self DatabaseExistsError) Error() string {
return string(self)
}
func NewDatabaseExistsError(db string) DatabaseExistsError {
return DatabaseExistsError(fmt.Sprintf("database %s exists", db))
}