Skip to content

Commit

Permalink
Merge pull request #113 from Ingenjorsarbete-For-Klimatet/feature/geo…
Browse files Browse the repository at this point in the history
…bounds
  • Loading branch information
mgcth authored Apr 6, 2024
2 parents 55f433c + 8e6477f commit 8ad7501
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/smhi/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,4 @@ def get_now() -> datetime:
STRANG_TIME_INTERVALS = ["hourly", "daily", "monthly"]

STATUS_OK = 200
OUT_OF_BOUNDS = "out of bounds"
8 changes: 6 additions & 2 deletions src/smhi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging

import requests
from smhi.constants import STATUS_OK
from smhi.constants import OUT_OF_BOUNDS, STATUS_OK

logger = logging.getLogger(__name__)

Expand All @@ -18,14 +18,18 @@ def get_request(url: str) -> requests.Response:
response
Raises:
ValueError
requests.exceptions.HTTPError
"""
logger.debug(f"Fetching from {url}.")

response = requests.get(url, timeout=200)

if response.status_code != STATUS_OK:
raise requests.exceptions.HTTPError(f"Could request from {url}.")
if OUT_OF_BOUNDS in response.text.lower():
raise ValueError("Request is out of bounds.")

raise requests.exceptions.HTTPError(f"Could not request from {url}.")

logger.debug(f"Successful request from {url}.")

Expand Down

0 comments on commit 8ad7501

Please sign in to comment.