From 7a8d8e3b7f00bfab93feb2af6c22ed3b2166afaf Mon Sep 17 00:00:00 2001 From: Maurice van Veen Date: Tue, 10 Sep 2024 18:10:48 +0200 Subject: [PATCH] Fix stream snapshot error messaging Signed-off-by: Maurice van Veen --- snapshots.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/snapshots.go b/snapshots.go index 7f8295b..3294b70 100644 --- a/snapshots.go +++ b/snapshots.go @@ -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 @@ -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 }