nats-io/natscli

req: set exit status based on: response / header existing

philpennock opened this issue · 0 comments

Proposed change

nats req foo input exits successfully always, even if it says No responders are available.

  1. nats req --fail-no-responder
  2. nats req --fail-if-header HDR

Use case

If not failing by default because "we talked to NATS fine" then we should have a flag for req of "exit failure from CLI tool if request did not have a responder". This will let us script based on "there was nothing there.

Second, if we're talking to a service then the service might respond indicating a failure, and use a NATS Header to report the header. One I'm looking at now uses Nats-Service-Error: some message and Nats-Service-Error-Code: 404 and then a JSON object to indicate the error in the payload. It would be really helpful if we could use a flag to cause nats req to exit indicating a failure if that this happened.

Ideally distinct error exit codes would be used for each of those two scenarios.

Contribution

I can do.