Merge pull request #98 from ucan-wg/container-err
container: clarify returned error
This commit is contained in:
@@ -2,7 +2,6 @@ package container
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"iter"
|
"iter"
|
||||||
@@ -101,14 +100,12 @@ func (ctn Reader) GetToken(cid cid.Cid) (token.Token, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetDelegation is the same as GetToken but only return a delegation.Token, with the right type.
|
// GetDelegation is the same as GetToken but only return a delegation.Token, with the right type.
|
||||||
|
// If not found, delegation.ErrDelegationNotFound is returned.
|
||||||
func (ctn Reader) GetDelegation(cid cid.Cid) (*delegation.Token, error) {
|
func (ctn Reader) GetDelegation(cid cid.Cid) (*delegation.Token, error) {
|
||||||
tkn, err := ctn.GetToken(cid)
|
tkn, err := ctn.GetToken(cid)
|
||||||
if errors.Is(err, ErrNotFound) {
|
if err != nil { // only ErrNotFound expected
|
||||||
return nil, delegation.ErrDelegationNotFound
|
return nil, delegation.ErrDelegationNotFound
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if tkn, ok := tkn.(*delegation.Token); ok {
|
if tkn, ok := tkn.(*delegation.Token); ok {
|
||||||
return tkn, nil
|
return tkn, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user