diff --git a/pkg/client/client.go b/pkg/client/client.go index 5f2308c..8da217c 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -2,6 +2,7 @@ package client import ( "context" + "errors" "fmt" "log/slog" "net/http" @@ -121,15 +122,17 @@ func (c *Client) ConnectAndRead(ctx context.Context, cursor *int64) error { c.con = con + var readErr = nil if err := c.readLoop(ctx); err != nil { - return fmt.Errorf("read loop failed: %w", err) + readErr = fmt.Errorf("read loop failed: %w", err) } + var closeErr = nil if err := c.con.Close(); err != nil { - return fmt.Errorf("failed to close connection: %w", err) + closeErr = fmt.Errorf("failed to close connection: %w", err) } - return nil + return errors.Join(readErr, closeErr) } func (c *Client) readLoop(ctx context.Context) error {