feat: Add custom exception handling to dataset router

Added custom exceptions for dataset router

Feature COG-502
This commit is contained in:
Igor Ilic 2024-11-27 15:57:37 +01:00
parent e67bd91bd2
commit 7d1210c889

View file

@ -156,18 +156,13 @@ def get_datasets_router() -> APIRouter:
dataset_data = await get_dataset_data(dataset.id)
if dataset_data is None:
raise HTTPException(status_code=404, detail=f"No data found in dataset ({dataset_id}).")
raise EntityNotFoundError(message=f"No data found in dataset ({dataset_id}).")
matching_data = [data for data in dataset_data if str(data.id) == data_id]
# Check if matching_data contains an element
if len(matching_data) == 0:
return JSONResponse(
status_code=404,
content={
"detail": f"Data ({data_id}) not found in dataset ({dataset_id})."
}
)
raise EntityNotFoundError(message= f"Data ({data_id}) not found in dataset ({dataset_id}).")
data = matching_data[0]