mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
feat: 优化下载错误码
This commit is contained in:
@@ -1 +1 @@
|
|||||||
v5.0.0-250813
|
v5.0.0-250814
|
||||||
|
|||||||
@@ -349,32 +349,32 @@ func DownloadFileByUrl(fileUrl string) (filePath string, err error) {
|
|||||||
// Build the HTTP GET request.
|
// Build the HTTP GET request.
|
||||||
req, err := http.NewRequest("GET", fileUrl, nil)
|
req, err := http.NewRequest("GET", fileUrl, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", errors.Wrap(code.NetworkError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform the request.
|
// Perform the request.
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", errors.Wrap(code.NetworkError, err.Error())
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
// Check the HTTP status code.
|
// Check the HTTP status code.
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return "", fmt.Errorf("failed to download file: %s", resp.Status)
|
return "", errors.Wrap(code.NetworkError, fmt.Errorf("failed to download file: %s", resp.Status).Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the output file.
|
// Create the output file.
|
||||||
outFile, err := os.Create(filePath)
|
outFile, err := os.Create(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", errors.Wrap(code.MobileUIDriverError, err.Error())
|
||||||
}
|
}
|
||||||
defer outFile.Close()
|
defer outFile.Close()
|
||||||
|
|
||||||
// Copy the response body to the file.
|
// Copy the response body to the file.
|
||||||
_, err = io.Copy(outFile, resp.Body)
|
_, err = io.Copy(outFile, resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", errors.Wrap(code.NetworkError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Str("filePath", filePath).Msg("download file success")
|
log.Info().Str("filePath", filePath).Msg("download file success")
|
||||||
|
|||||||
Reference in New Issue
Block a user