Merge pull request #6381 from gtirloni/issue-6380
HTTPDownloader - Fix invalid error handling
This commit is contained in:
commit
dcb870bcbf
|
@ -278,7 +278,10 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
|
|||
}
|
||||
|
||||
resp, err := httpClient.Do(req)
|
||||
if err == nil && (resp.StatusCode >= 200 && resp.StatusCode < 300) {
|
||||
if err != nil {
|
||||
log.Printf("[DEBUG] (download) Error making HTTP HEAD request: %s", err.Error())
|
||||
} else {
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
// If the HEAD request succeeded, then attempt to set the range
|
||||
// query if we can.
|
||||
if resp.Header.Get("Accept-Ranges") == "bytes" {
|
||||
|
@ -290,8 +293,9 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if err != nil || (resp.StatusCode >= 400 && resp.StatusCode < 600) {
|
||||
return fmt.Errorf("%s", resp.Status)
|
||||
} else {
|
||||
log.Printf("[DEBUG] (download) Unexpected HTTP response during HEAD request: %s", resp.Status)
|
||||
}
|
||||
}
|
||||
|
||||
// Set the request to GET now, and redo the query to download
|
||||
|
@ -300,8 +304,10 @@ func (d *HTTPDownloader) Download(dst *os.File, src *url.URL) error {
|
|||
resp, err = httpClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if err != nil || (resp.StatusCode >= 400 && resp.StatusCode < 600) {
|
||||
return fmt.Errorf("%s", resp.Status)
|
||||
} else {
|
||||
if resp.StatusCode >= 400 && resp.StatusCode < 600 {
|
||||
return fmt.Errorf("Error making HTTP GET request: %s", resp.Status)
|
||||
}
|
||||
}
|
||||
|
||||
d.total = d.current + uint64(resp.ContentLength)
|
||||
|
|
Loading…
Reference in New Issue