nats-io / nats-architecture-and-design

Architecture and Design Docs
Apache License 2.0
196 stars 21 forks source link

Support NATS error codes for JetStream interactions #11

Open ripienaar opened 3 years ago

ripienaar commented 3 years ago

Overview

Prefer NATS error codes when conditionally handling JetStream API errors and expose the code to users.

The basic idea is that in the past we would return errors like replicas > 1 not supported in non-clustered mode in the ApiErr and clients would parse these messages if they wanted to handle different errors differently.

Another case would be when accessing a consumer, you'd get a error like 404 but you would not know if this is due to a stream being missing or a consumer being missing.

We now have codes in addition to the errors, the replicas > 1 not supported in non-clustered mode has code 10074, libraries should check this code rather than parse the text. The error text is not part of the API promises and we need to be able to make changes to language, typos, etc.

The cli has nats error lookup 10074 to compliment these.

The behavior is documented in ADR-7, initial server PR https://github.com/nats-io/nats-server/pull/2168

Clients and Tools

Other Tasks

Client authors please update with your progress. If you open issues in your own repositories as a result of this request, please link them to this one by pasting the issue URL in a comment or main issue description.

wallyqs commented 2 years ago

Following releases of the Go client use errors wrapping for JetStream errors to capture APIError details: https://github.com/nats-io/nats.go/pull/1047