add context.Clean and correct rpc error code (#3295)

This commit is contained in:
Yingrong Zhao 2019-10-16 13:50:01 -04:00 committed by GitHub
parent 76ad83f12c
commit e5099f31f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import (
"go.uber.org/zap"
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/rpc/rpcstatus"
"storj.io/storj/storagenode/pieces"
"storj.io/storj/storagenode/satellites"
"storj.io/storj/storagenode/trust"
@ -48,7 +49,7 @@ func (e *Endpoint) GetNonExitingSatellites(ctx context.Context, req *pb.GetNonEx
// filter out satellites that are already exiting
exitingSatellites, err := e.satellites.ListGracefulExits(ctx)
if err != nil {
return nil, Error.Wrap(err)
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
}
for _, trusted := range trustedSatellites {
@ -95,20 +96,20 @@ func (e *Endpoint) InitiateGracefulExit(ctx context.Context, req *pb.InitiateGra
domain, err := e.trust.GetAddress(ctx, req.NodeId)
if err != nil {
e.log.Debug("initialize graceful exit: retrieve satellite address", zap.Error(err))
return nil, errs.Wrap(err)
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
}
// get space usage by satellites
spaceUsed, err := e.usageCache.SpaceUsedBySatellite(ctx, req.NodeId)
if err != nil {
e.log.Debug("initialize graceful exit: retrieve space used", zap.String("Satellite ID", req.NodeId.String()), zap.Error(err))
return nil, errs.Wrap(err)
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
}
err = e.satellites.InitiateGracefulExit(ctx, req.NodeId, time.Now().UTC(), spaceUsed)
if err != nil {
e.log.Debug("initialize graceful exit: save info into satellites table", zap.String("Satellite ID", req.NodeId.String()), zap.Error(err))
return nil, errs.Wrap(err)
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
}
return &pb.ExitProgress{
@ -122,7 +123,7 @@ func (e *Endpoint) InitiateGracefulExit(ctx context.Context, req *pb.InitiateGra
func (e *Endpoint) GetExitProgress(ctx context.Context, req *pb.GetExitProgressRequest) (*pb.GetExitProgressResponse, error) {
exitProgress, err := e.satellites.ListGracefulExits(ctx)
if err != nil {
return nil, errs.Wrap(err)
return nil, rpcstatus.Error(rpcstatus.Internal, err.Error())
}
resp := &pb.GetExitProgressResponse{

View File

@ -73,6 +73,7 @@ func TestInitiateGracefulExit(t *testing.T) {
func TestGetExitProgress(t *testing.T) {
ctx := testcontext.New(t)
defer ctx.Cleanup()
totalSatelliteCount := 3
planet, err := testplanet.New(t, totalSatelliteCount, 1, 1)