Skip to content

Commit

Permalink
Add config error exception to handle 422 status code (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaasnicolaas authored Jan 17, 2024
1 parent a2bb7c2 commit 1831ecb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion forecast_solar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

from .exceptions import (
ForecastSolarAuthenticationError,
ForecastSolarConfigError,
ForecastSolarConnectionError,
ForecastSolarError,
ForecastSolarRequestError,
ForecastSolarRatelimit,
ForecastSolarRequestError,
)
from .models import Estimate, Ratelimit

Expand Down Expand Up @@ -120,6 +121,10 @@ async def _request(
data = await response.json()
raise ForecastSolarAuthenticationError(data["message"])

if response.status == 422:
data = await response.text()
raise ForecastSolarConfigError(data)

if response.status == 429:
data = await response.json()
raise ForecastSolarRatelimit(data["message"])
Expand Down
8 changes: 8 additions & 0 deletions forecast_solar/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class ForecastSolarConnectionError(ForecastSolarError):
"""Forecast.Solar API connection exception."""


class ForecastSolarConfigError(ForecastSolarError):
"""Forecast.Solar API configuration exception."""

def __init__(self, data: str) -> None:
"""Init a solar config error."""
super().__init__(f"{data} (error 422)")


class ForecastSolarAuthenticationError(ForecastSolarError):
"""Forecast.Solar API authentication exception."""

Expand Down

0 comments on commit 1831ecb

Please sign in to comment.