Skip to content

Commit

Permalink
Merge branch 'main' into add-sql-user
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanyu66 authored May 6, 2024
2 parents e77fcbd + ac67823 commit 06ee1fc
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions internal/util/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
package util

import (
"encoding/xml"
"fmt"
"io"
"net/http"
"os"
"path/filepath"

"github.com/go-resty/resty/v2"
)

// GetResponse returns the response of a given URL
// GetResponse returns the response of a given AWS per-signed URL
func GetResponse(url string, debug bool) (*http.Response, error) {
httpClient := resty.New()
httpClient.SetDebug(debug)
Expand All @@ -32,8 +34,22 @@ func GetResponse(url string, debug bool) (*http.Response, error) {
return nil, err
}
if resp.StatusCode != http.StatusOK {
// read the body to get the error message
body, err := io.ReadAll(resp.Body)
resp.Body.Close()
return nil, fmt.Errorf("receiving status of %d for url: %s", resp.StatusCode, url)
if err != nil {
return nil, fmt.Errorf("receiving status of %d", resp.StatusCode)
}
type AwsError struct {
Code string `xml:"Code"`
Message string `xml:"Message"`
}
v := AwsError{}
err = xml.Unmarshal(body, &v)
if err != nil {
return nil, fmt.Errorf("receiving status of %d", resp.StatusCode)
}
return nil, fmt.Errorf("receiving status of %d. code:%s, message: %s", resp.StatusCode, v.Code, v.Message)
}
if resp.ContentLength <= 0 {
resp.Body.Close()
Expand Down

0 comments on commit 06ee1fc

Please sign in to comment.