more error checking
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m40s
Run linting on the backend code / Build (pull_request) Successful in 28s
Run testing on the backend code / Build (pull_request) Failing after 1m23s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 15s

This commit is contained in:
Helldragon67 2024-12-13 07:48:39 +01:00
parent edf2f3af72
commit f0873ff313
4 changed files with 16 additions and 9 deletions

File diff suppressed because one or more lines are too long

View File

@ -69,7 +69,7 @@ def new_trip(preferences: Preferences,
osm_id=0,
attractiveness=0,
must_do=True,
n_tags = 0)
n_tags=0)
# Generate the landmarks from the start location
landmarks, landmarks_short = manager.generate_landmarks_list(
@ -132,6 +132,8 @@ def get_landmark(landmark_uuid: str) -> Landmark:
"""
try:
landmark = cache_client.get(f"landmark_{landmark_uuid}")
if not isinstance(landmark, Landmark) :
raise ValueError(f"Object {landmark} is not of type Landmark")
return landmark
except KeyError as exc:
raise HTTPException(status_code=404, detail="Landmark not found") from exc

View File

@ -73,8 +73,6 @@ class Landmark(BaseModel) :
t_to_next_str = f", time_to_next={self.time_to_reach_next}" if self.time_to_reach_next else ""
is_secondary_str = ", secondary" if self.is_secondary else ""
type_str = '(' + self.type + ')'
if self.type in ["start", "finish", "nature", "shopping"] :
type_str += '\t '
return (f'Landmark{type_str}: [{self.name} @{self.location}, '
f'score={self.attractiveness}{t_to_next_str}{is_secondary_str}]')

View File

@ -1,4 +1,5 @@
"""Helper methods for testing."""
import logging
from typing import List
from fastapi import HTTPException
@ -31,17 +32,23 @@ def fetch_landmark(client, landmark_uuid: str):
Returns:
dict: Landmark data fetched from the API.
"""
logger = logging.getLogger(__name__)
response = client.get(f"/landmark/{landmark_uuid}")
if response.status_code != 200:
raise HTTPException(status_code=999,
raise HTTPException(status_code=500,
detail=f"Failed to fetch landmark with UUID {landmark_uuid}: {response.status_code}")
json_data = response.json()
try:
json_data = response.json()
logger.info(f"API Response: {json_data}")
print(f"API Response of type {type(json_data)} in json format: {json_data}")
except ValueError as e:
logger.error(f"Failed to parse response as JSON: {response.text}")
raise HTTPException(status_code=500, detail="Invalid response format from API")
if "detail" in json_data:
raise HTTPException(status_code=999, detail=json_data["detail"])
raise HTTPException(status_code=500, detail=json_data["detail"])
return json_data