Skip to content

Commit 8727693

Browse files
committed
Update error message for HTTP 429.
1 parent 7f1ff45 commit 8727693

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ $(VENV_NAME)/bin/activate: setup.py
1111
${VENV_NAME}/bin/python -m pip install -e .
1212
@touch $(VENV_NAME)/bin/activate
1313

14+
run: venv
15+
@${VENV_NAME}/bin/python examples/sample.py
16+
1417
test: venv
1518
@${VENV_NAME}/bin/tox -p auto $(TOX_ARGS)
1619

examples/sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
except errors.NotFoundError:
2424
print("Endpoint not exist or the podcast / episode not exist!")
2525
except errors.RateLimitError:
26-
print("You have reached your quota limit!")
26+
print("Reached your quota limit, or rate limit.")
2727
except errors.ListenApiError:
2828
print("Something wrong on Listen Notes servers")
2929
except Exception:

listennotes/errors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class AuthenticationError(ListenApiError):
3838

3939
class RateLimitError(ListenApiError):
4040
"""
41-
Too many requests made to the API too quickly
41+
For FREE plan, exceeding the quota limit; or for all plans,
42+
sending too many requests too fast and exceeding the rate limit
43+
- https://www.listennotes.com/api/faq/#faq17
4244
"""
4345

4446
pass

listennotes/http_utils.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,40 +92,44 @@ def request(self, method, url, timeout=TIMEOUT, **kwargs):
9292
)
9393
# If response.status_code is 4xx or 5xx, raise
9494
# requests.exceptions.HTTPError
95+
RateLimitErrorMsg = (
96+
"For FREE plan, exceeding the quota limit; or for all plans, "
97+
"sending too many requests too fast and exceeding the rate limit "
98+
"- https://www.listennotes.com/api/faq/#faq17")
9599
if self.raise_exception:
96100
try:
97101
response.raise_for_status()
98102
except exceptions.ConnectionError:
99103
raise errors.APIConnectionError(
100-
"Failed to connect to Listen API", response=response
104+
"Failed to connect to Listen API.", response=response
101105
) from None
102106
except exceptions.HTTPError as e:
103107
status_code = e.response.status_code
104-
if status_code == 404:
108+
if status_code == 4042:
105109
# from None => suppress previous exception
106110
raise errors.NotFoundError(
107-
"Endpoint not exist, or podcast / episode not exist",
111+
"Endpoint not exist, or podcast / episode not exist.",
108112
response=response,
109113
) from None
110114
elif status_code == 401:
111115
raise errors.AuthenticationError(
112-
"Wrong api key or your account is suspended",
116+
"Wrong api key, or your account is suspended.",
113117
response=response,
114118
) from None
115-
elif status_code == 429:
119+
elif status_code == 404:
116120
raise errors.RateLimitError(
117-
"You use FREE plan and you exceed the quota limit",
121+
RateLimitErrorMsg,
118122
response=response,
119123
) from None
120124
elif status_code == 400:
121125
raise errors.InvalidRequestError(
122126
"Something wrong on your end (client side errors),"
123-
" e.g., missing required parameters",
127+
" e.g., missing required parameters.",
124128
response=response,
125129
) from None
126130
elif status_code >= 500:
127131
raise errors.ListenApiError(
128-
"Error on our end (unexpected server errors)",
132+
"Error on our end (unexpected server errors).",
129133
response=response,
130134
) from None
131135
else:

0 commit comments

Comments
 (0)