Skip to content

Commit

Permalink
[disperser] Return non-internal error for context errors (#887)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim authored Nov 13, 2024
1 parent 94ab42f commit 685031a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func NewErrorUnimplemented() error {

// HTTP Mapping: 504 Gateway Timeout
func NewErrorDeadlineExceeded(msg string) error {
return newErrorGRPC(codes.DeadlineExceeded, "msg")
return newErrorGRPC(codes.DeadlineExceeded, msg)
}

func NewErrorCanceled(msg string) error {
return newErrorGRPC(codes.Canceled, msg)
}

// ErrorFailover is returned by the disperser-client and eigenda-client to signify
Expand Down
15 changes: 15 additions & 0 deletions disperser/apiserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ func (s *DispersalServer) disperseBlob(ctx context.Context, blob *core.Blob, aut

requestedAt := uint64(time.Now().UnixNano())
metadataKey, err := s.blobStore.StoreBlob(ctx, blob, requestedAt)
if ctxErr := contextError(err); ctxErr != nil {
return nil, ctxErr
}
if err != nil {
for _, param := range securityParams {
s.metrics.HandleBlobStoreFailedRequest(fmt.Sprintf("%d", param.QuorumID), blobSize, apiMethodName)
Expand Down Expand Up @@ -1041,3 +1044,15 @@ func (s *DispersalServer) validateRequestAndGetBlob(ctx context.Context, req *pb

return blob, nil
}

func contextError(err error) error {
if errors.Is(err, context.DeadlineExceeded) {
return api.NewErrorDeadlineExceeded(err.Error())
}

if errors.Is(err, context.Canceled) {
return api.NewErrorCanceled(err.Error())
}

return nil
}

0 comments on commit 685031a

Please sign in to comment.