From f16388f23831a80e08aebee56c0bf5b569c6d12e Mon Sep 17 00:00:00 2001 From: Artem Piskun Date: Thu, 9 Dec 2021 14:38:29 +0300 Subject: [PATCH] Handle TooManyRequests error (#53) --- discogs.go | 2 ++ errors.go | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/discogs.go b/discogs.go index 73fac98..86c6f02 100644 --- a/discogs.go +++ b/discogs.go @@ -105,6 +105,8 @@ func request(path string, params url.Values, resp interface{}) error { switch response.StatusCode { case http.StatusUnauthorized: return ErrUnauthorized + case http.StatusTooManyRequests: + return ErrTooManyRequests default: return fmt.Errorf("unknown error: %s", response.Status) } diff --git a/errors.go b/errors.go index ed7d9a4..bbbcc5a 100644 --- a/errors.go +++ b/errors.go @@ -16,10 +16,11 @@ func (e *Error) Error() string { // APIErrors var ( - ErrUnauthorized = &Error{"authentication required"} ErrCurrencyNotSupported = &Error{"currency does not supported"} - ErrUserAgentInvalid = &Error{"invalid user-agent"} ErrInvalidReleaseID = &Error{"invalid release id"} ErrInvalidSortKey = &Error{"invalid sort key"} ErrInvalidUsername = &Error{"invalid username"} + ErrTooManyRequests = &Error{"too many requests"} + ErrUnauthorized = &Error{"authentication required"} + ErrUserAgentInvalid = &Error{"invalid user-agent"} )