Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #128 from nats-io/err_handler
Browse files Browse the repository at this point in the history
add an async error handler to the NATS connection
  • Loading branch information
ripienaar authored Mar 23, 2020
2 parents bab1a6e + 94841ca commit 45a69d5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions nats/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}),
}
Expand Down

0 comments on commit 45a69d5

Please sign in to comment.