Skip to content

Commit 2c44ada

Browse files
authored
Discover RPC NOT_FOUND result tweaks (#154)
* Discover RPC returns OK when there's an empty list * Discover RPC returns NOT_FOUND for unimplemented categories
1 parent abcfb31 commit 2c44ada

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

ocp/rpc/currency/discovery.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,23 @@ func (s *currencyServer) Discover(req *currencypb.DiscoverRequest, stream curren
4242
return time.Since(record.CreatedAt) < newDiscoveredCurrenciesAgeLimit
4343
}
4444
default:
45-
return status.Error(codes.InvalidArgument, "invalid category")
45+
return stream.Send(&currencypb.DiscoverResponse{
46+
Result: currencypb.DiscoverResponse_NOT_FOUND,
47+
})
4648
}
4749

4850
metadataRecords, err := s.mintDataProvider.GetAllCachedCurrencyMetadata(ctx)
4951
if err == currency.ErrNotFound {
5052
return stream.Send(&currencypb.DiscoverResponse{
51-
Result: currencypb.DiscoverResponse_NOT_FOUND,
53+
Result: currencypb.DiscoverResponse_OK,
5254
})
5355
} else if err != nil {
5456
log.With(zap.Error(err)).Warn("failure getting currency metadata records")
5557
return status.Error(codes.Internal, "")
5658
}
5759
if len(metadataRecords) == 0 {
5860
return stream.Send(&currencypb.DiscoverResponse{
59-
Result: currencypb.DiscoverResponse_NOT_FOUND,
61+
Result: currencypb.DiscoverResponse_OK,
6062
})
6163
}
6264

@@ -106,7 +108,7 @@ func (s *currencyServer) Discover(req *currencypb.DiscoverRequest, stream curren
106108

107109
if len(candidates) == 0 {
108110
return stream.Send(&currencypb.DiscoverResponse{
109-
Result: currencypb.DiscoverResponse_NOT_FOUND,
111+
Result: currencypb.DiscoverResponse_OK,
110112
})
111113
}
112114

@@ -137,12 +139,6 @@ func (s *currencyServer) Discover(req *currencypb.DiscoverRequest, stream curren
137139
protoMints = append(protoMints, protoMint)
138140
}
139141

140-
if len(protoMints) == 0 {
141-
return stream.Send(&currencypb.DiscoverResponse{
142-
Result: currencypb.DiscoverResponse_NOT_FOUND,
143-
})
144-
}
145-
146142
return stream.Send(&currencypb.DiscoverResponse{
147143
Result: currencypb.DiscoverResponse_OK,
148144
Mints: protoMints,

0 commit comments

Comments
 (0)