mirror of
https://github.com/1f349/go-webdav.git
synced 2024-12-22 00:04:19 +00:00
internal: check for HTTP errors in Client.Do
Closes: https://github.com/emersion/go-webdav/issues/19
This commit is contained in:
parent
59ad6f4d76
commit
6de76c94b8
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user