Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

409 is a better error code IMNSHO #483

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -251,7 +251,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))
}