Skip to content

Commit

Permalink
Create channel log for full all sending errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Feb 16, 2018
1 parent 2f681b5 commit 3ae371d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions channel_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ func NewChannelLogFromRR(description string, channel Channel, msgID MsgID, rr *u
return log
}

// NewChannelLogFromError creates a new channel log for the passed in channel, msg id and error
func NewChannelLogFromError(description string, channel Channel, msgID MsgID, elapsed time.Duration, err error) *ChannelLog {
log := &ChannelLog{
Description: description,
Channel: channel,
MsgID: msgID,
Error: err.Error(),
CreatedOn: time.Now(),
Elapsed: elapsed,
}

return log
}

// WithError augments the passed in ChannelLog with the passed in description and error if error is not nil
func (l *ChannelLog) WithError(description string, err error) *ChannelLog {
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (w *Sender) sendMessage(msg Msg) {
msgLog.WithError(err).WithField("elapsed", duration).Error("error sending message")
if status == nil {
status = backend.NewMsgStatusForID(msg.Channel(), msg.ID(), MsgErrored)
status.AddLog(NewChannelLogFromError("Sending Error", msg.Channel(), msg.ID(), duration, err))
}
}

Expand Down
1 change: 1 addition & 0 deletions sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestSending(t *testing.T) {
assert.Equal(1, len(mb.msgStatuses))
assert.Equal(msg.ID(), mb.msgStatuses[0].ID())
assert.Equal(MsgErrored, mb.msgStatuses[0].Status())
assert.Equal(1, len(mb.msgStatuses[0].Logs()))

// clear our statuses
mb.msgStatuses = nil
Expand Down

0 comments on commit 3ae371d

Please sign in to comment.