Skip to content

Commit

Permalink
Code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vurpo committed Jul 6, 2023
1 parent d0d641d commit 1278ac4
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1412,9 +1412,6 @@ func (cli *Client) doMediaRequest(req *http.Request, retries int, backoff time.D
startTime := time.Now()
res, err := cli.Client.Do(req)
duration := time.Now().Sub(startTime)
if res != nil {
defer res.Body.Close()
}
if err != nil {
if retries > 0 {
return cli.doMediaRetry(req, err, retries, backoff)
Expand All @@ -1429,6 +1426,7 @@ func (cli *Client) doMediaRequest(req *http.Request, retries int, backoff time.D
cli.LogRequestDone(req, res, err, nil, 0, duration)
return nil, err
}
defer res.Body.Close()

if retries > 0 && cli.shouldRetry(res) {
if res.StatusCode == http.StatusTooManyRequests {
Expand All @@ -1437,8 +1435,8 @@ func (cli *Client) doMediaRequest(req *http.Request, retries int, backoff time.D
return cli.doMediaRetry(req, fmt.Errorf("HTTP %d", res.StatusCode), retries, backoff)
}

var body []byte
if res.StatusCode < 200 || res.StatusCode >= 300 {
var body []byte
body, err = ParseErrorResponse(req, res)
cli.LogRequestDone(req, res, err, nil, len(body), duration)
} else {
Expand All @@ -1452,14 +1450,12 @@ func (cli *Client) downloadContext(ctx context.Context, mxcURL id.ContentURI) (*
if ctxLog.GetLevel() == zerolog.Disabled || ctxLog == zerolog.DefaultContextLogger {
ctx = cli.Log.WithContext(ctx)
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, cli.GetDownloadURL(mxcURL), nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", cli.UserAgent+" (media downloader)")
resp, err := cli.doMediaRequest(req, cli.DefaultHTTPRetries, 4*time.Second)
return resp, err
return cli.doMediaRequest(req, cli.DefaultHTTPRetries, 4*time.Second)
}

func (cli *Client) DownloadBytes(mxcURL id.ContentURI) ([]byte, error) {
Expand Down

0 comments on commit 1278ac4

Please sign in to comment.