error handling and remove from cache
This commit is contained in:
@@ -2,6 +2,7 @@ from typing import Any
|
||||
|
||||
import requests_cache
|
||||
from partitions import location_partitions_def
|
||||
from requests import Request
|
||||
from retry_requests import retry
|
||||
from utils import parse_coord
|
||||
|
||||
@@ -67,7 +68,15 @@ def raw_weather(context: dg.AssetExecutionContext) -> Any:
|
||||
# print(len(responses))
|
||||
# print(responses)
|
||||
|
||||
response = retry_session.get(url, params=params)
|
||||
request = retry_session.prepare_request(Request("GET", url, params=params))
|
||||
cache_key = requests_cache.create_key(request)
|
||||
response = retry_session.send(request)
|
||||
response.raise_for_status()
|
||||
response.json()
|
||||
|
||||
data = response.json()
|
||||
if "error" in data:
|
||||
requests_cache.delete(cache_key)
|
||||
raise ValueError(
|
||||
f"Error (data['error']) fetching weather data: {data.get('reason', '')}"
|
||||
)
|
||||
return response.json()
|
||||
|
||||
Reference in New Issue
Block a user