Skip to content

Commit

Permalink
Fix stream snapshot error messaging
Browse files Browse the repository at this point in the history
Signed-off-by: Maurice van Veen <[email protected]>
  • Loading branch information
MauriceVanVeen committed Sep 10, 2024
1 parent a94b384 commit 7a8d8e3
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 @@ -396,17 +397,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 7a8d8e3

Please sign in to comment.