mirror of
https://codeberg.org/video-prize-ranch/rimgo.git
synced 2025-12-13 19:55:21 +00:00
Add error page for ratelimit
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user