vartanbeno / go-reddit

Go library for accessing the Reddit API.
Other
306 stars 84 forks source link

Response doesn't have api call body if reddit reports no rate limit left, even if api call was successful #48

Open sesopenko opened 3 months ago

sesopenko commented 3 months ago

When making an api call, if reddit reports there's no rate limit left (ie: you just used up the last api call for the 10 minute period), the library doesn't bother building a response using the response body, instead short circuiting out with a RateLimitError.

It checks the response, but if there is a header from the reddit api saying there's no rate limit remaining, it will return an error. See here:

https://github.com/vartanbeno/go-reddit/blob/master/reddit/reddit.go#L450

It will return an empty response object, without reading any response body from the reddit api, which is a bug. See here:

https://github.com/vartanbeno/go-reddit/blob/master/reddit/reddit.go#L366

It should only return an empty response body if there's no body from reddit. As the rate limit is reduced by each api call for the 10 minute period, the last api call will incorrectly return an error.