From 6eb8ae50d530930954827afe2d359acebcf91021 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Mon, 28 Jan 2019 08:02:42 +0000 Subject: [PATCH] simplify stan handler error handling --- stan.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/stan.go b/stan.go index be052b7..e48c6e2 100644 --- a/stan.go +++ b/stan.go @@ -224,14 +224,16 @@ func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...bro fn := func(msg *stan.Msg) { var m broker.Message - var err error - if err = n.opts.Codec.Unmarshal(msg.Data, &m); err != nil { + + // unmarshal message + if err := n.opts.Codec.Unmarshal(msg.Data, &m); err != nil { return } - err = handler(&publication{m: &m, msg: msg, t: msg.Subject}) - if err == nil && successAutoAck && !opt.AutoAck { - msg.Ack() - } else if err != nil && opt.AutoAck { + + // execute the handler + err := handler(&publication{m: &m, msg: msg, t: msg.Subject}) + // if there's no error and success auto ack is enabled ack it + if err == nil && successAutoAck { msg.Ack() } }