2021-02-23 09:58:06 +08:00
|
|
|
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:
|
2021-03-10 22:06:22 +08:00
|
|
|
if resp.GetStatus().ErrorCode != commonpb.ErrorCode_Success {
|
2021-02-23 09:58:06 +08:00
|
|
|
return errors.New(resp.GetStatus().Reason)
|
|
|
|
}
|
|
|
|
case *commonpb.Status:
|
2021-03-10 22:06:22 +08:00
|
|
|
if resp.ErrorCode != commonpb.ErrorCode_Success {
|
2021-02-23 09:58:06 +08:00
|
|
|
return errors.New(resp.Reason)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return errors.New("unknown response type")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|