Skip to content

Commit 08126f5

Browse files
committed
🐛 enhance publisher data formatting
1 parent c6c538f commit 08126f5

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

Diff for: pragma/client/client.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,32 @@ async def _make_request(self, path: str, params: dict[str, Any] | None = None) -
5252
try:
5353
return response.json()
5454
except ValueError as e:
55+
logger.error(f"Failed to parse JSON response: {response.text}")
5556
raise HTTPException(
5657
status_code=500,
57-
detail="Invalid JSON response from API",
58+
detail=f"Invalid JSON response from API: {response.text[:200]}",
5859
) from e
5960

6061
# Handle specific error cases
61-
if error_data and "message" in error_data and "No checkpoints found" in error_data["message"]:
62-
# Return empty array for "No checkpoints found" error
63-
return []
62+
if error_data and "message" in error_data:
63+
if "No checkpoints found" in error_data["message"]:
64+
return []
65+
# Return the actual error message from the API
66+
raise HTTPException(status_code=response.status_code, detail=error_data["message"])
6467

6568
# Handle other errors
6669
detail = (
6770
f"External API error: {error_data.get('error', 'Unknown error')}"
6871
if error_data
69-
else "Failed to fetch data from external API"
72+
else f"Failed to fetch data from external API: {response.text[:200]}"
7073
)
7174
raise HTTPException(status_code=response.status_code, detail=detail)
7275

7376
except httpx.RequestError as exc:
74-
logger.error(f"Request error: {exc}")
77+
logger.error(f"Request error for {url}: {exc}")
7578
raise HTTPException(
7679
status_code=500,
77-
detail=f"Error connecting to external API: {str(exc)}",
80+
detail=f"Error connecting to external API ({url}): {str(exc)}",
7881
) from exc
7982
except Exception as exc:
8083
logger.error(f"Unexpected error: {exc}", exc_info=True)

Diff for: pragma/routers/endpoints/onchain.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,29 @@ async def get_onchain_data(
110110
tags=["onchain"],
111111
)
112112
async def get_publishers(
113-
network: str = Query("sepolia", description="Network name", regex="^(sepolia|mainnet)$"),
113+
network: str = Query("sepolia", description="Network name"),
114114
data_type: str = Query(
115115
"spot_entry",
116116
description="Data type",
117-
regex="^(spot_entry|perp_entry|future_entry)$",
118117
),
119118
client: PragmaApiClient = Depends(get_api_client),
120119
):
121-
"""Retrieve publishers for a specific network and data type.
120+
"""Retrieve publishers for a specific network and data type."""
121+
publishers = await client.get_publishers(network, data_type)
122122

123-
Args:
124-
network: The network to fetch data from (sepolia or mainnet)
125-
data_type: The data type to filter by (spot_entry, perp_entry, or future_entry)
126-
client: The API client dependency
127-
Returns:
128-
List of publishers
129-
"""
130-
return await client.get_publishers(network, data_type)
123+
formatted_publishers = []
124+
for publisher in publishers:
125+
formatted_publisher = {
126+
"image": f"/assets/publishers/{publisher['publisher'].lower()}.svg",
127+
"type": publisher.get("type", ""),
128+
"link": publisher.get("website_url", ""),
129+
"name": publisher["publisher"],
130+
"lastUpdated": publisher.get("last_updated_timestamp", 0), # Just the raw timestamp
131+
"reputationScore": "soon",
132+
"nbFeeds": publisher.get("nb_feeds", 0),
133+
"dailyUpdates": publisher.get("daily_updates", 0),
134+
"totalUpdates": publisher.get("total_updates", 0),
135+
}
136+
formatted_publishers.append(formatted_publisher)
137+
138+
return formatted_publishers

0 commit comments

Comments
 (0)