milvus/internal/dataservice/util.go
xige-16 09ae985daa Fix wrong error code in master_service_test.go
Signed-off-by: xige-16 <xi.ge@zilliz.com>
2021-03-10 22:06:22 +08:00

34 lines
679 B
Go

package dataservice
import (
"errors"
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
)
type Response interface {
GetStatus() *commonpb.Status
}
func VerifyResponse(response interface{}, err error) error {
if err != nil {
return err
}
if response == nil {
return errors.New("response is nil")
}
switch resp := response.(type) {
case Response:
if resp.GetStatus().ErrorCode != commonpb.ErrorCode_Success {
return errors.New(resp.GetStatus().Reason)
}
case *commonpb.Status:
if resp.ErrorCode != commonpb.ErrorCode_Success {
return errors.New(resp.Reason)
}
default:
return errors.New("unknown response type")
}
return nil
}