mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 04:49:08 +08:00
09ae985daa
Signed-off-by: xige-16 <xi.ge@zilliz.com>
34 lines
679 B
Go
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
|
|
}
|