Undo error cause changes due to broken logic in other places, check for ConflictError explicitly

This commit is contained in:
Cody Soyland 2021-01-07 14:49:18 -06:00
parent 219714a18e
commit d8ebfda1bd
No known key found for this signature in database
GPG key ID: 6F5D2986DCC5DC8A
2 changed files with 5 additions and 16 deletions

View file

@ -105,11 +105,6 @@ func NewBadRequestError(err error) BadRequestError {
return BadRequestError{err}
}
// Cause satisfies the error causer interface
func (e BadRequestError) Cause() error {
return e.error
}
// ConflictError wraps an error value to signify that a conflict with an
// existing resource occurred such that in an HTTP scenario, http.StatusConflict
// would be returned.
@ -122,11 +117,6 @@ func newConflictError(err error) ConflictError {
return ConflictError{err}
}
// Cause satisfies the error causer interface
func (e ConflictError) Cause() error {
return e.error
}
// NotFoundError wraps an error value to signify that a resource was not found
// such that in an HTTP scenario, http.StatusNotFound would be returned.
type NotFoundError error
@ -145,11 +135,6 @@ func newPreconditionFailedError(err error) PreconditionFailedError {
return PreconditionFailedError{err}
}
// Cause satisfies the error causer interface
func (e PreconditionFailedError) Cause() error {
return e.error
}
// Regular expression to validate index and field names.
var nameRegexp = regexp.MustCompile(`^[a-z][a-z0-9_-]{0,229}$`)

View file

@ -68,7 +68,7 @@ func errToStatusError(err error) error {
}
// Check error string.
switch errors.Cause(err) {
switch cause := errors.Cause(err); cause {
case pilosa.ErrIndexNotFound,
pilosa.ErrFieldNotFound,
pilosa.ErrForeignIndexNotFound,
@ -123,6 +123,10 @@ func errToStatusError(err error) error {
pilosa.ErrTooManyWrites,
pilosa.ErrNodeIDNotExists:
return status.Error(codes.Internal, err.Error())
default:
if _, ok := cause.(pilosa.ConflictError); ok {
return status.Error(codes.AlreadyExists, err.Error())
}
}
return status.Error(codes.Unknown, err.Error())