github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/message/errors.go (about) 1 package message 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 var ( 9 ErrUnauthorizedUnicastOnChannel = errors.New("message is not authorized to be sent on channel via unicast") 10 ErrUnauthorizedPublishOnChannel = errors.New("message is not authorized to be sent on channel via publish/multicast") 11 ErrUnauthorizedMessageOnChannel = errors.New("message is not authorized to be sent on channel") 12 ErrUnauthorizedRole = errors.New("sender role not authorized to send message on channel") 13 ) 14 15 // UnknownMsgTypeErr indicates that no message auth configured for the message type v 16 type UnknownMsgTypeErr struct { 17 MsgType interface{} 18 } 19 20 func (e UnknownMsgTypeErr) Error() string { 21 return fmt.Sprintf("could not get authorization config for unknown message type: %T", e.MsgType) 22 } 23 24 // NewUnknownMsgTypeErr returns a new ErrUnknownMsgType 25 func NewUnknownMsgTypeErr(msgType interface{}) UnknownMsgTypeErr { 26 return UnknownMsgTypeErr{MsgType: msgType} 27 } 28 29 // IsUnknownMsgTypeErr returns whether an error is UnknownMsgTypeErr 30 func IsUnknownMsgTypeErr(err error) bool { 31 var e UnknownMsgTypeErr 32 return errors.As(err, &e) 33 } 34 35 // NewUnauthorizedProtocolError returns ErrUnauthorizedUnicastOnChannel or ErrUnauthorizedPublishOnChannel depending on the protocol provided. 36 func NewUnauthorizedProtocolError(p ProtocolType) error { 37 if p == ProtocolTypeUnicast { 38 return ErrUnauthorizedUnicastOnChannel 39 } 40 41 return ErrUnauthorizedPublishOnChannel 42 }