github.com/koko1123/flow-go-1@v0.29.6/network/p2p/scoring/invalid_subscription_error.go (about)

     1  package scoring
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  // InvalidSubscriptionError indicates that a peer has subscribed to a topic that is not allowed for its role.
     9  type InvalidSubscriptionError struct {
    10  	topic string // the topic that the peer is subscribed to, but not allowed to.
    11  }
    12  
    13  func NewInvalidSubscriptionError(topic string) error {
    14  	return InvalidSubscriptionError{
    15  		topic: topic,
    16  	}
    17  }
    18  
    19  func (e InvalidSubscriptionError) Error() string {
    20  	return fmt.Sprintf("unauthorized subscription: %s", e.topic)
    21  }
    22  
    23  func IsInvalidSubscriptionError(this error) bool {
    24  	var e InvalidSubscriptionError
    25  	return errors.As(this, &e)
    26  }