github.com/wfusion/gofusion@v1.1.14/common/infra/watermill/pkg/publisher/errors.go (about)

     1  package publisher
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/wfusion/gofusion/common/infra/watermill/message"
     7  )
     8  
     9  type ErrCouldNotPublish struct {
    10  	reasons map[string]error
    11  }
    12  
    13  func (e *ErrCouldNotPublish) addMsg(msg *message.Message, reason error) {
    14  	e.reasons[msg.UUID] = reason
    15  }
    16  
    17  func NewErrCouldNotPublish() *ErrCouldNotPublish {
    18  	return &ErrCouldNotPublish{make(map[string]error)}
    19  }
    20  
    21  func (e ErrCouldNotPublish) Len() int {
    22  	return len(e.reasons)
    23  }
    24  
    25  func (e ErrCouldNotPublish) Error() string {
    26  	if len(e.reasons) == 0 {
    27  		return ""
    28  	}
    29  	b := strings.Builder{}
    30  	b.WriteString("Could not publish the messages:\n")
    31  	for uuid, reason := range e.reasons {
    32  		b.WriteString(uuid + " : " + reason.Error() + "\n")
    33  	}
    34  	return b.String()
    35  }
    36  
    37  func (e ErrCouldNotPublish) Reasons() map[string]error {
    38  	return e.reasons
    39  }