Skip to content

Commit

Permalink
feat: type switch recover
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Oct 28, 2020
1 parent 2d97ab5 commit 10c8ac8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,22 @@ func (c *Consumer) OnReceive(queue *Queue, receiveMsg *ReceiveMessage) {
go func() {
defer func() {
if p := recover(); p != nil {
e, _ := p.(error)
var err error
switch pt := p.(type) {
case string:
{
err = errors.New(pt)
}
case error:
{
err = pt
}
default:
err = errors.New("unknown err")
}
c.logger.Warn(
fmt.Sprintf("handler crashed, queue = %s", queue.Name),
zap.Error(e),
zap.Error(err),
zap.String("body", receiveMsg.MessageBody),
zap.String("message_id", receiveMsg.MessageID),
zap.String("receipt_handle", receiveMsg.ReceiptHandle),
Expand Down

0 comments on commit 10c8ac8

Please sign in to comment.