Skip to content

Commit

Permalink
Rename the ratelimit exception (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaasnicolaas authored May 2, 2024
1 parent 4ffa970 commit 7a55014
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime, timezone, timedelta
from pprint import pprint

from forecast_solar import ForecastSolar, ForecastSolarRatelimit
from forecast_solar import ForecastSolar, ForecastSolarRatelimitError


async def main():
Expand All @@ -19,7 +19,7 @@ async def main():
) as forecast:
try:
estimate = await forecast.estimate()
except ForecastSolarRatelimit as err:
except ForecastSolarRatelimitError as err:
print("Ratelimit reached")
print(f"Rate limit resets at {err.reset_at}")
reset_period = err.reset_at - datetime.now(timezone.utc)
Expand Down
4 changes: 2 additions & 2 deletions src/forecast_solar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ForecastSolarConfigError,
ForecastSolarAuthenticationError,
ForecastSolarRequestError,
ForecastSolarRatelimit,
ForecastSolarRatelimitError,
)
from .models import Estimate, AccountType, Ratelimit
from .forecast_solar import ForecastSolar
Expand All @@ -19,7 +19,7 @@
"ForecastSolarConfigError",
"ForecastSolarConnectionError",
"ForecastSolarError",
"ForecastSolarRatelimit",
"ForecastSolarRatelimitError",
"ForecastSolarRequestError",
"Ratelimit",
]
2 changes: 1 addition & 1 deletion src/forecast_solar/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, data: dict) -> None:
self.code = data["code"]


class ForecastSolarRatelimit(ForecastSolarRequestError):
class ForecastSolarRatelimitError(ForecastSolarRequestError):
"""Forecast.Solar maximum number of requests reached exception."""

def __init__(self, data: dict) -> None:
Expand Down
6 changes: 3 additions & 3 deletions src/forecast_solar/forecast_solar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ForecastSolarConfigError,
ForecastSolarConnectionError,
ForecastSolarError,
ForecastSolarRatelimit,
ForecastSolarRatelimitError,
ForecastSolarRequestError,
)
from .models import Estimate, Ratelimit
Expand Down Expand Up @@ -74,7 +74,7 @@ async def _request(
Forecast.Solar API.
ForecastSolarRequestError: There is something wrong with the
variables used in the request.
ForecastSolarRatelimit: The number of requests has exceeded
ForecastSolarRatelimitError: The number of requests has exceeded
the rate limit of the Forecast.Solar API.
"""

Expand Down Expand Up @@ -132,7 +132,7 @@ async def _request(

if response.status == 429:
data = await response.json()
raise ForecastSolarRatelimit(data["message"])
raise ForecastSolarRatelimitError(data["message"])

if rate_limit and response.status < 500:
self.ratelimit = Ratelimit.from_response(response)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from forecast_solar import (
ForecastSolar,
ForecastSolarRatelimit,
ForecastSolarRatelimitError,
ForecastSolarConfigError,
ForecastSolarAuthenticationError,
ForecastSolarRequestError,
Expand Down Expand Up @@ -103,7 +103,7 @@ async def test_status_429(
text=load_fixtures("ratelimit.json"),
),
)
with pytest.raises(ForecastSolarRatelimit):
with pytest.raises(ForecastSolarRatelimitError):
assert await forecast_client._request("test")


Expand Down

0 comments on commit 7a55014

Please sign in to comment.