From a11466bd138ca363169a3e7a4e89218ee0bc6931 Mon Sep 17 00:00:00 2001 From: Olof-Joachim Frahm Date: Wed, 20 Dec 2017 10:53:49 +0100 Subject: [PATCH] Handle error response when reading a file. --- client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 754330f..958fb0c 100644 --- a/client.go +++ b/client.go @@ -261,7 +261,12 @@ func (c *Client) ReadStream(path string) (io.ReadCloser, error) { if err != nil { return nil, newPathErrorErr("ReadStream", path, err) } - return rs.Body, nil + if rs.StatusCode == 200 { + return rs.Body, nil + } else { + rs.Body.Close() + return nil, newPathError("ReadStream", path, rs.StatusCode) + } } func (c *Client) Write(path string, data []byte, _ os.FileMode) error {