Skip to content

Commit

Permalink
feat: additional error checks after queue subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
smlx committed Mar 16, 2022
1 parent 999ab04 commit 1f1f930
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/sshportalapi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,21 @@ func ServeNATS(ctx context.Context, stop context.CancelFunc, log *zap.Logger,
}
defer nc.Close()
// set up request/response callback for sshportal
_, err = nc.QueueSubscribe(SubjectSSHAccessQuery, queue,
sub, err := nc.QueueSubscribe(SubjectSSHAccessQuery, queue,
sshportal(ctx, log, nc, l, k))
if err != nil {
return fmt.Errorf("couldn't subscribe to queue: %v", err)
}
// additional error checks
if err = nc.Flush(); err != nil {
return fmt.Errorf("couldn't flush connection after subscribe: %v", err)
}
if err = nc.LastError(); err != nil {
return fmt.Errorf("connection error after subscribe: %v", err)
}
if !sub.IsValid() {
return fmt.Errorf("invalid subscription")
}
// wait for context cancellation
<-ctx.Done()
// drain and log errors
Expand Down

0 comments on commit 1f1f930

Please sign in to comment.