Use 429 error page for 429 errors from Imgur API

This commit is contained in:
video-prize-ranch 2022-10-05 22:16:57 -04:00
parent cdbd3944d9
commit 740ae0d925
No known key found for this signature in database
GPG Key ID: D8EAA4C5B12A7281
1 changed files with 6 additions and 3 deletions

View File

@ -44,9 +44,12 @@ func GetJSON(url string) (gjson.Result, error) {
return gjson.Result{}, err return gjson.Result{}, err
} }
if res.StatusCode != 200 { switch (res.StatusCode) {
case 200:
return gjson.Parse(string(body)), nil
case 429:
return gjson.Result{}, fmt.Errorf("ratelimited by imgur")
default:
return gjson.Result{}, fmt.Errorf("received status %s, expected 200 OK.\n%s", res.Status, string(body)) return gjson.Result{}, fmt.Errorf("received status %s, expected 200 OK.\n%s", res.Status, string(body))
} }
return gjson.Parse(string(body)), nil
} }