Add error page for ratelimit

This commit is contained in:
video-prize-ranch
2022-09-10 10:11:17 -04:00
parent f0c1b7f4fe
commit 1263e66f45
6 changed files with 54 additions and 27 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"io"
"net/http"
"strconv"
"github.com/tidwall/gjson"
)
@@ -30,6 +31,13 @@ func GetJSON(url string) (gjson.Result, error) {
if err != nil {
return gjson.Result{}, err
}
rateLimitRemaining := res.Header.Get("X-RateLimit-UserRemaining")
if rateLimitRemaining != "" {
ratelimit, _ := strconv.Atoi(rateLimitRemaining)
if ratelimit <= 0 {
return gjson.Result{}, fmt.Errorf("ratelimited by imgur")
}
}
body, err := io.ReadAll(res.Body)
if err != nil {