6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-25 16:28:20 +00:00

Don't double log errors in Request()

This commit is contained in:
James Mills 2022-03-20 01:24:21 +10:00
parent e602f0f3ce
commit 158c7f9231

@ -69,8 +69,7 @@ func RenderString(s string, ctx interface{}) (string, error) {
func Request(method, uri string, headers http.Header, body io.Reader) (*http.Response, error) {
req, err := http.NewRequest(method, uri, body)
if err != nil {
log.WithError(err).Errorf("%s: http.NewRequest fail: %s", uri, err)
return nil, err
return nil, fmt.Errorf("%s: http.NewRequest fail: %s", uri, err)
}
if headers == nil {
@ -90,14 +89,11 @@ func Request(method, uri string, headers http.Header, body io.Reader) (*http.Res
res, err := client.Do(req)
if err != nil {
log.WithError(err).Errorf("%s: client.Do fail: %s", uri, err)
return nil, err
return nil, fmt.Errorf("%s: client.Do fail: %s", uri, err)
}
if res.StatusCode/100 != 2 {
err = fmt.Errorf("non-2xx response received: %s", res.Status)
log.Errorf("%s: request returned an error: %s", uri, err)
return nil, err
return nil, fmt.Errorf("non-2xx response received: %s", res.Status)
}
return res, nil