satellite/metainfo: better metabase errors handling
Some errors were returned as metabase errors, not pure drpc errors because of how rpcstatus.Code method is working. Status code was returned for errors like metabase context canceled but we would like to not leak our internals to the client. Change-Id: I3f0194755f8d7359b1e3d342fa3be3d984019ecb
This commit is contained in:
parent
b4c95a3b28
commit
c9591e9754
@ -5,6 +5,7 @@ package metainfo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@ -298,12 +299,16 @@ func (endpoint *Endpoint) unmarshalSatSegmentID(ctx context.Context, segmentID s
|
||||
|
||||
// convertMetabaseErr converts domain errors from metabase to appropriate rpc statuses errors.
|
||||
func (endpoint *Endpoint) convertMetabaseErr(err error) error {
|
||||
if rpcstatus.Code(err) != rpcstatus.Unknown {
|
||||
switch {
|
||||
case err == nil:
|
||||
return nil
|
||||
case errors.Is(err, context.Canceled):
|
||||
return rpcstatus.Error(rpcstatus.Canceled, "context canceled")
|
||||
case errors.Is(err, context.DeadlineExceeded):
|
||||
return rpcstatus.Error(rpcstatus.DeadlineExceeded, "context deadline exceeded")
|
||||
case rpcstatus.Code(err) != rpcstatus.Unknown:
|
||||
// it's already RPC error
|
||||
return err
|
||||
}
|
||||
|
||||
switch {
|
||||
case metabase.ErrObjectNotFound.Has(err):
|
||||
message := strings.TrimPrefix(err.Error(), string(metabase.ErrObjectNotFound))
|
||||
message = strings.TrimPrefix(message, ": ")
|
||||
|
Loading…
Reference in New Issue
Block a user