Skip to content

Commit

Permalink
Merge pull request #573 from nats-io/fix/stream-snapshot-error-messaging
Browse files Browse the repository at this point in the history
Fix stream snapshot error messaging
  • Loading branch information
ripienaar authored Dec 17, 2024
2 parents d30372b + 7a8d8e3 commit 2a95464
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type snapshotOptions struct {
}

const (
ClientInfoHdr string = "Nats-Request-Info"
StatusHdr string = "Status"
DescriptionHdr string = "Description"
)

// ErrMemoryStreamNotSupported is an error indicating a memory stream was being snapshotted which is not supported
Expand Down Expand Up @@ -397,17 +398,16 @@ func (s *Stream) createSnapshot(ctx context.Context, dataBuffer, metadataBuffer

sub, err := s.mgr.nc.Subscribe(ib, func(m *nats.Msg) {
if len(m.Data) == 0 {
m.Sub.Unsubscribe()
cancel()

clientInfoHeader := m.Header.Get(ClientInfoHdr)
statusValue := m.Header.Get(StatusHdr)

// if the server returns a non-204 status code in the message header, return an error
if clientInfoHeader != "" && !strings.Contains(clientInfoHeader, "204") {
errc <- errors.New(clientInfoHeader)
return
if statusValue != "" && !strings.Contains(statusValue, "204") {
descriptionValue := m.Header.Get(DescriptionHdr)
errc <- fmt.Errorf("%s %s", statusValue, descriptionValue)
}

m.Sub.Unsubscribe()
cancel()
return
}

Expand Down

0 comments on commit 2a95464

Please sign in to comment.