Skip to content

Commit 38fcabc

Browse files
authored
Merge pull request #33 from EO-DataHub/patch/32-server-responds-with-a-500-if-the-airbus-api-key-is-invalid
bug: adds error handling when accessing Airbus API with invalid key
2 parents 68526a3 + 0949694 commit 38fcabc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.1.26 (2025-10-23)
4+
5+
Improved Airbus country code response when an invalid token is provided
6+
37
## v0.1.25 (2025-07-01)
48

59
- Geometry for ordered items are clipped by an AOI if provided

resource_catalogue_fastapi/airbus_client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ def validate_country_code(self, country_code: str):
6060
access_token = self.generate_access_token()
6161
headers = {"Authorization": f"Bearer {access_token}"}
6262
properties_response = requests.get(url, headers=headers)
63-
properties = properties_response.json().get("properties")
63+
64+
if properties_response.status_code != 200:
65+
try:
66+
j = properties_response.json()
67+
except requests.exceptions.JSONDecodeError:
68+
j = {"message": "Unknown error"}
69+
70+
message = j.get("message", "Unknown error")
71+
raise HTTPException(status_code=400, detail=message)
72+
73+
properties = properties_response.json().get("properties", [])
6474

6575
countries = next((prop["values"] for prop in properties if prop["key"] == "countries"), [])
6676
country_ids = [country["id"] for country in countries]

0 commit comments

Comments
 (0)