Skip to content

Commit

Permalink
fix(api): parsing body before checking status and not using the logge…
Browse files Browse the repository at this point in the history
…r in GlobalAPIService
  • Loading branch information
lemilonkh committed Jan 10, 2025
1 parent a02c13a commit 63ba131
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/src/backend/GlobalAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ export class GlobalAPIService {
const URL = `${GLOBAL_API_URL}/api/v0/ghgi/emissions_forecast/city/${encodeURIComponent(locode)}/${forecastYear}`;
const response = await fetch(URL);
logger.info(`${URL} Response Status: ${response.status}`);
const data = await response.json();
if (response.status !== 200) {
return undefined;
}

const data = await response.json();
return {
...data,
growthRates: data.growth_rates,
};
} catch (error) {
console.error(`Error fetching growth rates: ${error}`);
logger.error(`Error fetching growth rates: ${error}`);
return undefined;
}
}
Expand Down

0 comments on commit 63ba131

Please sign in to comment.