internal: check for HTTP errors in Client.Do

Closes: https://github.com/emersion/go-webdav/issues/19
This commit is contained in:
Simon Ser 2020-01-22 13:22:45 +01:00
parent 59ad6f4d76
commit 6de76c94b8
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -67,7 +67,16 @@ func (c *Client) Do(req *http.Request) (*http.Response, error) {
if c.username != "" || c.password != "" {
req.SetBasicAuth(c.username, c.password)
}
return c.http.Do(req)
resp, err := c.http.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode/100 != 2 {
// TODO: if body is plaintext, read it and populate the error message
resp.Body.Close()
return nil, &HTTPError{Code: resp.StatusCode}
}
return resp, nil
}
func (c *Client) DoMultiStatus(req *http.Request) (*Multistatus, error) {