mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-28 13:48:49 +08:00

* Return Auth service Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Compose to run with SpiceDB and Auth svc Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update auth gRPC API Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove Users' policies Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Move Groups to internal Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use shared groups in Users Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove unused code Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use pkg Groups in Things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove Things groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Make imports consistent Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Groups networking Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove things groups-specific API Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Move Things Clients to the root Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Move Clients to Users root Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Temporarily remove tracing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix imports Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add buffer config for gRPC Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update auth type for Things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use Auth for login Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add temporary solution for refresh token Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Tokenizer interface Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Updade tokens issuing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix token issuing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update JWT validator and refactor Tokenizer Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Rename access timeout Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Rename login to authenticate Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Identify to use SubjectID Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add Auth to Groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use the Auth service for Groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update auth schema Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix Auth for Groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add auth for addons (#14) Signed-off-by: Arvindh <arvindh91@gmail.com> Speparate Login and Refresh tokens Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Merge authN and authZ requests for things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add connect and disconnect Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update sharing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix policies addition and removal Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update relation with roels Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add gRPC to Things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Assign and Unassign members to group and Listing of Group members (#15) * add auth for addons Signed-off-by: Arvindh <arvindh91@gmail.com> * add assign and unassign to group Signed-off-by: Arvindh <arvindh91@gmail.com> * add group incomplete repo implementation Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Move coap mqtt and ws policies to spicedb (#16) Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Remove old policies Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> NOISSUE - Things authorize to return thingID (#18) This commit modifies the authorize endpoint to the grpc endpoint to return thingID. The authorize endpoint allows adapters to get the publisher of the message. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Add Groups to users service (#17) * add assign and unassign to group Signed-off-by: Arvindh <arvindh91@gmail.com> * add group incomplete repo implementation Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users stable 1 Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users stable 2 Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users & things Signed-off-by: Arvindh <arvindh91@gmail.com> * Amend signature Signed-off-by: Arvindh <arvindh91@gmail.com> * fix merge error Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Fix es code (#21) Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Fix Bugs (#20) * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Test e2e (#19) * fix: connect method Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * fix: e2e Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * fix changes in sdk and e2e Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(docker): remove unnecessary port mapping Remove the port mapping for MQTT broker in the docker-compose.yml file. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Enable group listing Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(responses): update ChannelsPage struct The ChannelsPage struct in the responses.go file has been updated. The "Channels" field has been renamed to "Groups" to provide more accurate naming. This change ensures consistency and clarity in the codebase. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(things): add UpdateClientSecret method Add the UpdateClientSecret method to the things service. This method allows updating the client secret for a specific client identified by the provided token, id, and key parameters. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Use smaller buffers for gRPC Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Clean up tests (#22) Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add Connect Disconnect endpoints (#23) * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: Things share with users (#25) * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> * add: things share with other users Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Rename gRPC Services (#24) * Rename things and users auth service Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * docs: add authorization docs for gRPC services Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Rename things and users grpc services Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Remove mainflux.env package Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: Listing of things, channels, groups, users (#26) * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Clean Up Users (#27) * feat(groups): rename redis package to events - Renamed the `redis` package to `events` in the `internal/groups` directory. - Updated the file paths and names accordingly. - This change reflects the more accurate purpose of the package and improves code organization. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(auth): Modify identity method Change request and response of identity method Add accessToken and refreshToken to Token response Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * clean up users, remove dead code Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(users): add unit tests for user service This commit adds unit tests for the user service in the `users` package. The tests cover various scenarios and ensure the correct behavior of the service. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: List of user groups & removed repeating code in groups (#29) * removed repeating code in list groups Signed-off-by: Arvindh <arvindh91@gmail.com> * add: list of user group Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: otel handler operator name for endpoints Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Clean Up Things Service (#28) * Rework things service Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * add tests Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Clean Up Auth Service (#30) * clean up auth service Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(auth): remove unused import Remove the unused import of `emptypb` in `auth.pb.go`. This import is not being used in the codebase and can be safely removed. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Update API docs (#31) Signed-off-by: rodneyosodo <blackd0t@protonmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Remove TODO comments and cleanup the code Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Update dependenices Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: rodneyosodo <blackd0t@protonmail.com> Co-authored-by: b1ackd0t <28790446+rodneyosodo@users.noreply.github.com> Co-authored-by: Arvindh <30824765+arvindh123@users.noreply.github.com>
236 lines
12 KiB
Go
236 lines
12 KiB
Go
// Copyright 2020-2022 The NATS Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package nats
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
// API errors
|
|
|
|
// ErrJetStreamNotEnabled is an error returned when JetStream is not enabled for an account.
|
|
ErrJetStreamNotEnabled JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeJetStreamNotEnabled, Description: "jetstream not enabled", Code: 503}}
|
|
|
|
// ErrJetStreamNotEnabledForAccount is an error returned when JetStream is not enabled for an account.
|
|
ErrJetStreamNotEnabledForAccount JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeJetStreamNotEnabledForAccount, Description: "jetstream not enabled for account", Code: 503}}
|
|
|
|
// ErrStreamNotFound is an error returned when stream with given name does not exist.
|
|
ErrStreamNotFound JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeStreamNotFound, Description: "stream not found", Code: 404}}
|
|
|
|
// ErrStreamNameAlreadyInUse is returned when a stream with given name already exists and has a different configuration.
|
|
ErrStreamNameAlreadyInUse JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeStreamNameInUse, Description: "stream name already in use", Code: 400}}
|
|
|
|
// ErrStreamSubjectTransformNotSupported is returned when the connected nats-server version does not support setting
|
|
// the stream subject transform. If this error is returned when executing AddStream(), the stream with invalid
|
|
// configuration was already created in the server.
|
|
ErrStreamSubjectTransformNotSupported JetStreamError = &jsError{message: "stream subject transformation not supported by nats-server"}
|
|
|
|
// ErrStreamSourceSubjectTransformNotSupported is returned when the connected nats-server version does not support setting
|
|
// the stream source subject transform. If this error is returned when executing AddStream(), the stream with invalid
|
|
// configuration was already created in the server.
|
|
ErrStreamSourceSubjectTransformNotSupported JetStreamError = &jsError{message: "stream subject transformation not supported by nats-server"}
|
|
|
|
// ErrStreamSourceNotSupported is returned when the connected nats-server version does not support setting
|
|
// the stream sources. If this error is returned when executing AddStream(), the stream with invalid
|
|
// configuration was already created in the server.
|
|
ErrStreamSourceNotSupported JetStreamError = &jsError{message: "stream sourcing is not supported by nats-server"}
|
|
|
|
// ErrStreamSourceMultipleSubjectTransformsNotSupported is returned when the connected nats-server version does not support setting
|
|
// the stream sources. If this error is returned when executing AddStream(), the stream with invalid
|
|
// configuration was already created in the server.
|
|
ErrStreamSourceMultipleSubjectTransformsNotSupported JetStreamError = &jsError{message: "stream sourceing with multiple subject transforms not supported by nats-server"}
|
|
|
|
// ErrConsumerNotFound is an error returned when consumer with given name does not exist.
|
|
ErrConsumerNotFound JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeConsumerNotFound, Description: "consumer not found", Code: 404}}
|
|
|
|
// ErrMsgNotFound is returned when message with provided sequence number does npt exist.
|
|
ErrMsgNotFound JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeMessageNotFound, Description: "message not found", Code: 404}}
|
|
|
|
// ErrBadRequest is returned when invalid request is sent to JetStream API.
|
|
ErrBadRequest JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeBadRequest, Description: "bad request", Code: 400}}
|
|
|
|
// ErrDuplicateFilterSubjects is returned when both FilterSubject and FilterSubjects are specified when creating consumer.
|
|
ErrDuplicateFilterSubjects JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeDuplicateFilterSubjects, Description: "consumer cannot have both FilterSubject and FilterSubjects specified", Code: 500}}
|
|
|
|
// ErrDuplicateFilterSubjects is returned when filter subjects overlap when creating consumer.
|
|
ErrOverlappingFilterSubjects JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeOverlappingFilterSubjects, Description: "consumer subject filters cannot overlap", Code: 500}}
|
|
|
|
// ErrEmptyFilter is returned when a filter in FilterSubjects is empty.
|
|
ErrEmptyFilter JetStreamError = &jsError{apiErr: &APIError{ErrorCode: JSErrCodeConsumerEmptyFilter, Description: "consumer filter in FilterSubjects cannot be empty", Code: 500}}
|
|
|
|
// Client errors
|
|
|
|
// ErrConsumerNameAlreadyInUse is an error returned when consumer with given name already exists.
|
|
ErrConsumerNameAlreadyInUse JetStreamError = &jsError{message: "consumer name already in use"}
|
|
|
|
// ErrConsumerNotActive is an error returned when consumer is not active.
|
|
ErrConsumerNotActive JetStreamError = &jsError{message: "consumer not active"}
|
|
|
|
// ErrInvalidJSAck is returned when JetStream ack from message publish is invalid.
|
|
ErrInvalidJSAck JetStreamError = &jsError{message: "invalid jetstream publish response"}
|
|
|
|
// ErrStreamConfigRequired is returned when empty stream configuration is supplied to add/update stream.
|
|
ErrStreamConfigRequired JetStreamError = &jsError{message: "stream configuration is required"}
|
|
|
|
// ErrStreamNameRequired is returned when the provided stream name is empty.
|
|
ErrStreamNameRequired JetStreamError = &jsError{message: "stream name is required"}
|
|
|
|
// ErrConsumerNameRequired is returned when the provided consumer durable name is empty.
|
|
ErrConsumerNameRequired JetStreamError = &jsError{message: "consumer name is required"}
|
|
|
|
// ErrConsumerMultipleFilterSubjectsNotSupported is returned when the connected nats-server version does not support setting
|
|
// multiple filter subjects with filter_subjects field. If this error is returned when executing AddConsumer(), the consumer with invalid
|
|
// configuration was already created in the server.
|
|
ErrConsumerMultipleFilterSubjectsNotSupported JetStreamError = &jsError{message: "multiple consumer filter subjects not supported by nats-server"}
|
|
|
|
// ErrConsumerConfigRequired is returned when empty consumer consuguration is supplied to add/update consumer.
|
|
ErrConsumerConfigRequired JetStreamError = &jsError{message: "consumer configuration is required"}
|
|
|
|
// ErrPullSubscribeToPushConsumer is returned when attempting to use PullSubscribe on push consumer.
|
|
ErrPullSubscribeToPushConsumer JetStreamError = &jsError{message: "cannot pull subscribe to push based consumer"}
|
|
|
|
// ErrPullSubscribeRequired is returned when attempting to use subscribe methods not suitable for pull consumers for pull consumers.
|
|
ErrPullSubscribeRequired JetStreamError = &jsError{message: "must use pull subscribe to bind to pull based consumer"}
|
|
|
|
// ErrMsgAlreadyAckd is returned when attempting to acknowledge message more than once.
|
|
ErrMsgAlreadyAckd JetStreamError = &jsError{message: "message was already acknowledged"}
|
|
|
|
// ErrNoStreamResponse is returned when there is no response from stream (e.g. no responders error).
|
|
ErrNoStreamResponse JetStreamError = &jsError{message: "no response from stream"}
|
|
|
|
// ErrNotJSMessage is returned when attempting to get metadata from non JetStream message .
|
|
ErrNotJSMessage JetStreamError = &jsError{message: "not a jetstream message"}
|
|
|
|
// ErrInvalidStreamName is returned when the provided stream name is invalid (contains '.' or ' ').
|
|
ErrInvalidStreamName JetStreamError = &jsError{message: "invalid stream name"}
|
|
|
|
// ErrInvalidConsumerName is returned when the provided consumer name is invalid (contains '.' or ' ').
|
|
ErrInvalidConsumerName JetStreamError = &jsError{message: "invalid consumer name"}
|
|
|
|
// ErrNoMatchingStream is returned when stream lookup by subject is unsuccessful.
|
|
ErrNoMatchingStream JetStreamError = &jsError{message: "no stream matches subject"}
|
|
|
|
// ErrSubjectMismatch is returned when the provided subject does not match consumer's filter subject.
|
|
ErrSubjectMismatch JetStreamError = &jsError{message: "subject does not match consumer"}
|
|
|
|
// ErrContextAndTimeout is returned when attempting to use both context and timeout.
|
|
ErrContextAndTimeout JetStreamError = &jsError{message: "context and timeout can not both be set"}
|
|
|
|
// ErrCantAckIfConsumerAckNone is returned when attempting to ack a message for consumer with AckNone policy set.
|
|
ErrCantAckIfConsumerAckNone JetStreamError = &jsError{message: "cannot acknowledge a message for a consumer with AckNone policy"}
|
|
|
|
// ErrConsumerDeleted is returned when attempting to send pull request to a consumer which does not exist
|
|
ErrConsumerDeleted JetStreamError = &jsError{message: "consumer deleted"}
|
|
|
|
// ErrConsumerLeadershipChanged is returned when pending requests are no longer valid after leadership has changed
|
|
ErrConsumerLeadershipChanged JetStreamError = &jsError{message: "Leadership Changed"}
|
|
|
|
// ErrNoHeartbeat is returned when no heartbeat is received from server when sending requests with pull consumer.
|
|
ErrNoHeartbeat JetStreamError = &jsError{message: "no heartbeat received"}
|
|
|
|
// DEPRECATED: ErrInvalidDurableName is no longer returned and will be removed in future releases.
|
|
// Use ErrInvalidConsumerName instead.
|
|
ErrInvalidDurableName = errors.New("nats: invalid durable name")
|
|
)
|
|
|
|
// Error code represents JetStream error codes returned by the API
|
|
type ErrorCode uint16
|
|
|
|
const (
|
|
JSErrCodeJetStreamNotEnabledForAccount ErrorCode = 10039
|
|
JSErrCodeJetStreamNotEnabled ErrorCode = 10076
|
|
JSErrCodeInsufficientResourcesErr ErrorCode = 10023
|
|
|
|
JSErrCodeStreamNotFound ErrorCode = 10059
|
|
JSErrCodeStreamNameInUse ErrorCode = 10058
|
|
|
|
JSErrCodeConsumerNotFound ErrorCode = 10014
|
|
JSErrCodeConsumerNameExists ErrorCode = 10013
|
|
JSErrCodeConsumerAlreadyExists ErrorCode = 10105
|
|
JSErrCodeDuplicateFilterSubjects ErrorCode = 10136
|
|
JSErrCodeOverlappingFilterSubjects ErrorCode = 10138
|
|
JSErrCodeConsumerEmptyFilter ErrorCode = 10139
|
|
|
|
JSErrCodeMessageNotFound ErrorCode = 10037
|
|
|
|
JSErrCodeBadRequest ErrorCode = 10003
|
|
JSStreamInvalidConfig ErrorCode = 10052
|
|
|
|
JSErrCodeStreamWrongLastSequence ErrorCode = 10071
|
|
)
|
|
|
|
// APIError is included in all API responses if there was an error.
|
|
type APIError struct {
|
|
Code int `json:"code"`
|
|
ErrorCode ErrorCode `json:"err_code"`
|
|
Description string `json:"description,omitempty"`
|
|
}
|
|
|
|
// Error prints the JetStream API error code and description
|
|
func (e *APIError) Error() string {
|
|
return fmt.Sprintf("nats: %s", e.Description)
|
|
}
|
|
|
|
// APIError implements the JetStreamError interface.
|
|
func (e *APIError) APIError() *APIError {
|
|
return e
|
|
}
|
|
|
|
// Is matches against an APIError.
|
|
func (e *APIError) Is(err error) bool {
|
|
if e == nil {
|
|
return false
|
|
}
|
|
// Extract internal APIError to match against.
|
|
var aerr *APIError
|
|
ok := errors.As(err, &aerr)
|
|
if !ok {
|
|
return ok
|
|
}
|
|
return e.ErrorCode == aerr.ErrorCode
|
|
}
|
|
|
|
// JetStreamError is an error result that happens when using JetStream.
|
|
// In case of client-side error, `APIError()` returns nil
|
|
type JetStreamError interface {
|
|
APIError() *APIError
|
|
error
|
|
}
|
|
|
|
type jsError struct {
|
|
apiErr *APIError
|
|
message string
|
|
}
|
|
|
|
func (err *jsError) APIError() *APIError {
|
|
return err.apiErr
|
|
}
|
|
|
|
func (err *jsError) Error() string {
|
|
if err.apiErr != nil && err.apiErr.Description != "" {
|
|
return err.apiErr.Error()
|
|
}
|
|
return fmt.Sprintf("nats: %s", err.message)
|
|
}
|
|
|
|
func (err *jsError) Unwrap() error {
|
|
// Allow matching to embedded APIError in case there is one.
|
|
if err.apiErr == nil {
|
|
return nil
|
|
}
|
|
return err.apiErr
|
|
}
|