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

Carbon intensity fetchers should fail gracefully when external API's return statuscode 400 #67

Open
Snailed opened this issue Mar 1, 2024 · 0 comments

Comments

@Snailed
Copy link
Collaborator

Snailed commented Mar 1, 2024

When external API's return non-200 status codes, a JSON deserialization error is thrown.
This can be seen in issue #64.

Expected behavior is a relevant network error message for the user to act accordingly upon.

The problem can be seen in the following lines (can also be seen in the other fetchers)

def _emission_prognosis(self, time_dur):
from_str, to_str = self._interval(time_dur=time_dur)
url = "https://api.energidataservice.dk/dataset/CO2Emis?start={" + from_str + "&end={" + to_str + "}&limit=4"
response = requests.get(url)
if not response.ok:
raise exceptions.CarbonIntensityFetcherError(response.json())

The code throws an exception when computing response.json(), and thus does not raise a CarbonIntensityFetcherError as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant