[#149] object/search: Return fixed error if relation not found
Define ErrRelationNotFound error in searchsvc package. Return ErrRelationNotFound from RelationSearcher.SearchRelation method if search result is empty. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
2913aa0fd1
commit
5ad013c10b
1 changed files with 6 additions and 0 deletions
|
@ -17,6 +17,8 @@ type RelationSearcher struct {
|
||||||
queryGenerator func(*object.Address) query.Query
|
queryGenerator func(*object.Address) query.Query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ErrRelationNotFound = errors.New("relation not found")
|
||||||
|
|
||||||
func (s *RelationSearcher) SearchRelation(ctx context.Context, addr *object.Address, prm *util.CommonPrm) (*object.ID, error) {
|
func (s *RelationSearcher) SearchRelation(ctx context.Context, addr *object.Address, prm *util.CommonPrm) (*object.ID, error) {
|
||||||
streamer, err := s.svc.Search(ctx, new(Prm).
|
streamer, err := s.svc.Search(ctx, new(Prm).
|
||||||
WithContainerID(addr.GetContainerID()).WithCommonPrm(prm).
|
WithContainerID(addr.GetContainerID()).WithCommonPrm(prm).
|
||||||
|
@ -30,6 +32,10 @@ func (s *RelationSearcher) SearchRelation(ctx context.Context, addr *object.Addr
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "(%T) could not read full search stream", s)
|
return nil, errors.Wrapf(err, "(%T) could not read full search stream", s)
|
||||||
} else if ln := len(res); ln != 1 {
|
} else if ln := len(res); ln != 1 {
|
||||||
|
if ln == 0 {
|
||||||
|
return nil, ErrRelationNotFound
|
||||||
|
}
|
||||||
|
|
||||||
return nil, errors.Errorf("(%T) unexpected amount of found objects %d", s, ln)
|
return nil, errors.Errorf("(%T) unexpected amount of found objects %d", s, ln)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue