Skip to content

Commit

Permalink
MEX-666: Put the openexchangerates query inside a try catch block
Browse files Browse the repository at this point in the history
  • Loading branch information
EmanuelMiron committed Jan 30, 2025
1 parent 3b5b444 commit 2b72604
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@ export class CurrencyConverterComputeService {
params.symbols = symbols.join(',');
}

const response = await this.apiService.get(
'https://openexchangerates.org/api/latest.json',
{ params },
);
try {
const response = await this.apiService.get(
'https://openexchangerates.org/api/latest.json',
{ params },
);

return Object.entries(response.data.rates).map(([currency, rate]) => ({
currency,
rate: rate as number,
}));
return Object.entries(response.data.rates).map(
([currency, rate]) => ({
currency,
rate: rate as number,
}),
);
} catch (error) {
throw new Error(`Failed to fetch currency rates: ${error.message}`);
}
}
}

0 comments on commit 2b72604

Please sign in to comment.