1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-26 15:42:21 +08:00

fix blockservice error ignorance

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
Jeromy
2015-09-04 15:41:15 -07:00
parent 206739d10c
commit 4d8eddcebc

View File

@ -96,19 +96,25 @@ func (s *BlockService) GetBlock(ctx context.Context, k key.Key) (*blocks.Block,
block, err := s.Blockstore.Get(k) block, err := s.Blockstore.Get(k)
if err == nil { if err == nil {
return block, nil return block, nil
}
if err == blockstore.ErrNotFound && s.Exchange != nil {
// TODO be careful checking ErrNotFound. If the underlying // TODO be careful checking ErrNotFound. If the underlying
// implementation changes, this will break. // implementation changes, this will break.
} else if err == blockstore.ErrNotFound && s.Exchange != nil {
log.Debug("Blockservice: Searching bitswap.") log.Debug("Blockservice: Searching bitswap.")
blk, err := s.Exchange.GetBlock(ctx, k) blk, err := s.Exchange.GetBlock(ctx, k)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return blk, nil return blk, nil
} else { }
log.Debug("Blockservice GetBlock: Not found.")
log.Debug("Blockservice GetBlock: Not found.")
if err == blockstore.ErrNotFound {
return nil, ErrNotFound return nil, ErrNotFound
} }
return nil, err
} }
// GetBlocks gets a list of blocks asynchronously and returns through // GetBlocks gets a list of blocks asynchronously and returns through