From 94841caaa09e9a0eddc02719296be95703407287 Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Mon, 23 Mar 2020 17:19:25 +0100 Subject: [PATCH] add an async error handler to the NATS connection --- nats/util.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nats/util.go b/nats/util.go index ecb99cc..f1d7a06 100644 --- a/nats/util.go +++ b/nats/util.go @@ -279,10 +279,12 @@ func natsOpts() []nats.Option { nats.ReconnectHandler(func(nc *nats.Conn) { log.Printf("Reconnected [%s]", nc.ConnectedUrl()) }), - nats.ClosedHandler(func(nc *nats.Conn) { - err := nc.LastError() - if err != nil { - log.Fatalf("Exiting: %v", nc.LastError()) + nats.ErrorHandler(func(nc *nats.Conn, _ *nats.Subscription, err error) { + url := nc.ConnectedUrl() + if url == "" { + log.Printf("Unexpected NATS error: %s", err) + } else { + log.Printf("Unexpected NATS error from server %s: %s", url, err) } }), }