From 1db22e13bfcff1663049ab6bde85bc9c42c97832 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 26 Mar 2025 12:59:55 +0000 Subject: [PATCH] Add GET endpoint for /countries --- endpoints/countries.get.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/endpoints/countries.get.py b/endpoints/countries.get.py index fe67f6c..5ddc127 100644 --- a/endpoints/countries.get.py +++ b/endpoints/countries.get.py @@ -12,12 +12,10 @@ router = APIRouter() async def get_countries(): """Get list of countries from external API""" async with httpx.AsyncClient() as client: - try: - response = await client.get("https://restcountries.com/v3.1/all") - response.raise_for_status() - return response.json() - except httpx.HTTPError: + response = await client.get("https://restcountries.com/v3.1/all") + if response.status_code != 200: raise HTTPException( status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail="Unable to fetch countries from external API" - ) \ No newline at end of file + ) + return response.json() \ No newline at end of file