Skip to content

Commit

Permalink
Close #483. Return 409 if a database already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Muller authored and pauldix committed May 27, 2014
1 parent 24707c4 commit f24f54c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/api/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ func errorToStatusCode(err error) int {
return libhttp.StatusUnauthorized // HTTP 401
case AuthorizationError:
return libhttp.StatusForbidden // HTTP 403
case DatabaseExistsError:
return libhttp.StatusConflict // HTTP 409
default:
return libhttp.StatusBadRequest // HTTP 400
}
Expand Down
2 changes: 1 addition & 1 deletion src/cluster/cluster_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func (self *ClusterConfiguration) CreateDatabase(name string, replicationFactor
defer self.createDatabaseLock.Unlock()

if _, ok := self.DatabaseReplicationFactors[name]; ok {
return fmt.Errorf("database %s exists", name)
return common.NewDatabaseExistsError(name)
}
self.DatabaseReplicationFactors[name] = replicationFactor
return nil
Expand Down
10 changes: 10 additions & 0 deletions src/common/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ func (self AuthorizationError) Error() string {
func NewAuthorizationError(formatStr string, args ...interface{}) AuthorizationError {
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))
}

0 comments on commit f24f54c

Please sign in to comment.