only get parser when we actually need it

This commit is contained in:
Andre Medeiros 2021-07-15 13:40:29 -04:00
parent 9e77a662a3
commit 56d72d5dea

View file

@ -122,13 +122,13 @@ func (rac *AuthenticatedClient) request(r *Request, rh ResponseHandler, empty in
return nil, err
}
parser := rac.pool.Get()
defer rac.pool.Put(parser)
if resp.StatusCode != 200 {
rac.statsd.Incr("reddit.api.errors", r.tags, 0.1)
// Try to parse a json error. Otherwise we generate a generic one
parser := rac.pool.Get()
defer rac.pool.Put(parser)
val, jerr := parser.ParseBytes(bb)
if jerr != nil {
return nil, fmt.Errorf("error from reddit: %d", resp.StatusCode)
@ -140,6 +140,9 @@ func (rac *AuthenticatedClient) request(r *Request, rh ResponseHandler, empty in
return empty, nil
}
parser := rac.pool.Get()
defer rac.pool.Put(parser)
val, err := parser.ParseBytes(bb)
if err != nil {
return nil, err