mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-30 18:51:03 +00:00
Don't double log errors in Request()
This commit is contained in:
parent
e602f0f3ce
commit
158c7f9231
10
utils.go
10
utils.go
@ -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) {
|
func Request(method, uri string, headers http.Header, body io.Reader) (*http.Response, error) {
|
||||||
req, err := http.NewRequest(method, uri, body)
|
req, err := http.NewRequest(method, uri, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("%s: http.NewRequest fail: %s", uri, err)
|
return nil, fmt.Errorf("%s: http.NewRequest fail: %s", uri, err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if headers == nil {
|
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)
|
res, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("%s: client.Do fail: %s", uri, err)
|
return nil, fmt.Errorf("%s: client.Do fail: %s", uri, err)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.StatusCode/100 != 2 {
|
if res.StatusCode/100 != 2 {
|
||||||
err = fmt.Errorf("non-2xx response received: %s", res.Status)
|
return nil, fmt.Errorf("non-2xx response received: %s", res.Status)
|
||||||
log.Errorf("%s: request returned an error: %s", uri, err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user