1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-03-24 02:49:34 +00:00

Utils: Fixed a nil dereference bug

This commit is contained in:
diamondburned (Forefront) 2020-05-05 15:36:14 -07:00
parent 0c24ac627b
commit cb525ca5c0

View file

@ -151,7 +151,7 @@ func (c *Client) RequestJSON(to interface{}, method, url string, opts ...Request
} }
func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.Response, error) { func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.Response, error) {
var err error var doErr error
var r httpdriver.Response var r httpdriver.Response
var status int var status int
@ -166,7 +166,7 @@ func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.
return nil, errors.Wrap(err, "Failed to apply options") return nil, errors.Wrap(err, "Failed to apply options")
} }
r, err = c.Client.Do(q) r, doErr = c.Client.Do(q)
// Call OnResponse() even if the request failed. // Call OnResponse() even if the request failed.
for _, fn := range c.OnResponse { for _, fn := range c.OnResponse {
@ -175,7 +175,7 @@ func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.
} }
} }
if err != nil { if doErr != nil {
continue continue
} }
@ -187,8 +187,8 @@ func (c *Client) Request(method, url string, opts ...RequestOption) (httpdriver.
} }
// If all retries failed: // If all retries failed:
if err != nil { if doErr != nil {
return nil, RequestError{err} return nil, RequestError{doErr}
} }
// Response received, but with a failure status code: // Response received, but with a failure status code: