Add debug logging to IUCN API calls to inspect response structures.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e931b5ab-041b-42e7-baf1-50017869cef6
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/e19c6a51-7e4c-4bb8-a6a6-46dc00f0ec99/1cb15499-88b2-4bbc-afd6-845ffc4e44b5.jpg
This commit is contained in:
Magnus-SmariSma
2025-03-20 23:23:34 +00:00
parent 55c68a34a4
commit ecf40d5294

View File

@ -394,6 +394,11 @@ export async function registerRoutes(app: Express): Promise<Server> {
} }
}); });
// Debug the response structure
console.log("IUCN API response structure:",
Object.keys(response.data),
response.data.result ? `Result has ${response.data.result.length} items` : "No result property");
return res.json({ return res.json({
success: true, success: true,
data: response.data, data: response.data,
@ -471,12 +476,20 @@ export async function registerRoutes(app: Express): Promise<Server> {
const taxonId = taxaResponse.data.result[0].taxonid; const taxonId = taxaResponse.data.result[0].taxonid;
// Now retrieve the threats using the taxon ID // Now retrieve the threats using the taxon ID
const threatsResponse = await axios.get(`https://apiv4.iucnredlist.org/api/v4/threats/species/id/${taxonId}`, { const threatsResponse = await axios.get(`https://apiv4.iucnredlist.org/api/v4/threats`, {
headers: { headers: {
"Authorization": `Bearer ${activeToken.iucnToken}` "Authorization": `Bearer ${activeToken.iucnToken}`
},
params: {
taxonid: taxonId
} }
}); });
// Debug the response structure
console.log("IUCN Threats API response structure:",
Object.keys(threatsResponse.data),
threatsResponse.data.result ? `Result has ${threatsResponse.data.result.length} items` : "No result property");
return res.json({ return res.json({
success: true, success: true,
data: threatsResponse.data, data: threatsResponse.data,
@ -554,12 +567,20 @@ export async function registerRoutes(app: Express): Promise<Server> {
const taxonId = taxaResponse.data.result[0].taxonid; const taxonId = taxaResponse.data.result[0].taxonid;
// Now retrieve the habitats using the taxon ID // Now retrieve the habitats using the taxon ID
const habitatsResponse = await axios.get(`https://apiv4.iucnredlist.org/api/v4/habitats/species/id/${taxonId}`, { const habitatsResponse = await axios.get(`https://apiv4.iucnredlist.org/api/v4/habitats`, {
headers: { headers: {
"Authorization": `Bearer ${activeToken.iucnToken}` "Authorization": `Bearer ${activeToken.iucnToken}`
},
params: {
taxonid: taxonId
} }
}); });
// Debug the response structure
console.log("IUCN Habitats API response structure:",
Object.keys(habitatsResponse.data),
habitatsResponse.data.result ? `Result has ${habitatsResponse.data.result.length} items` : "No result property");
return res.json({ return res.json({
success: true, success: true,
data: habitatsResponse.data, data: habitatsResponse.data,