feat: 优化下载错误码

This commit is contained in:
余泓铮
2025-08-14 17:59:35 +08:00
parent 269867240f
commit 3a57eacfd3
2 changed files with 6 additions and 6 deletions

View File

@@ -1 +1 @@
v5.0.0-250813
v5.0.0-250814

View File

@@ -349,32 +349,32 @@ func DownloadFileByUrl(fileUrl string) (filePath string, err error) {
// Build the HTTP GET request.
req, err := http.NewRequest("GET", fileUrl, nil)
if err != nil {
return "", err
return "", errors.Wrap(code.NetworkError, err.Error())
}
// Perform the request.
resp, err := client.Do(req)
if err != nil {
return "", err
return "", errors.Wrap(code.NetworkError, err.Error())
}
defer resp.Body.Close()
// Check the HTTP status code.
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.
outFile, err := os.Create(filePath)
if err != nil {
return "", err
return "", errors.Wrap(code.MobileUIDriverError, err.Error())
}
defer outFile.Close()
// Copy the response body to the file.
_, err = io.Copy(outFile, resp.Body)
if err != nil {
return "", err
return "", errors.Wrap(code.NetworkError, err.Error())
}
log.Info().Str("filePath", filePath).Msg("download file success")