diff --git a/api/errors.go b/api/errors.go index bd4c278842..42632da105 100644 --- a/api/errors.go +++ b/api/errors.go @@ -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 diff --git a/disperser/apiserver/server.go b/disperser/apiserver/server.go index 001d663ed1..793de14857 100644 --- a/disperser/apiserver/server.go +++ b/disperser/apiserver/server.go @@ -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) @@ -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 +}