Enhance country data retrieval and error handling in WatchedMap component
- Improved country code extraction logic to handle null values and prevent rendering errors. - Added error handling for API responses to ensure graceful degradation in case of failures. - Updated the logic for determining country codes from GeoJSON features to account for missing values. - Set default values for watched items and summary to avoid application crashes during data fetch failures.
This commit is contained in:
@@ -218,7 +218,22 @@ async def get_musicbrainz_artist_country(mbid: str) -> Optional[str]:
|
||||
)
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
# Check area relations for country
|
||||
|
||||
# First, check direct country field
|
||||
if "country" in data and data["country"]:
|
||||
country = data["country"]
|
||||
if isinstance(country, str) and len(country) == 2:
|
||||
return country.upper()
|
||||
|
||||
# Second, check area.iso-3166-1-codes
|
||||
if "area" in data and data["area"]:
|
||||
area = data["area"]
|
||||
if "iso-3166-1-codes" in area and area["iso-3166-1-codes"]:
|
||||
codes = area["iso-3166-1-codes"]
|
||||
if isinstance(codes, list) and len(codes) > 0:
|
||||
return codes[0].upper()
|
||||
|
||||
# Third, check area relations for country
|
||||
if "relations" in data:
|
||||
for relation in data["relations"]:
|
||||
if relation.get("type") == "origin" and "area" in relation:
|
||||
|
||||
Reference in New Issue
Block a user