Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config error exception to handle 422 status code #39

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading