Close #483. Return 409 if a database already exist
parent
85e507242c
commit
d054713e63
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue