diff --git a/pilosa.go b/pilosa.go index 9188deaf4..a05228087 100644 --- a/pilosa.go +++ b/pilosa.go @@ -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}$`) diff --git a/server/grpc.go b/server/grpc.go index c2c24864d..13c9303f5 100644 --- a/server/grpc.go +++ b/server/grpc.go @@ -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())