forked from GoogleCloudPlatform/microservices-demo
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
Issue Description
The currencyservice is failing to convert currencies to GBP, causing errors and switching back to the original currency.
Root Cause
In the currency_conversion.json
file, the GBP currency rate is set to an empty string:
"GBP": "",
This causes the conversion calculation to return zero when attempting to convert to GBP, which triggers the error handling code in the convert
function in server.js
:
// Check if the result is zero
if (result.units === 0 && result.nanos === 0) {
logger.error(`Currency conversion resulted in zero amount, switching back to original currency`);
notifySlack();
// Switch back to the original currency
result.currency_code = request.from.currency_code;
result.units = request.from.units;
result.nanos = request.from.nanos;
callback(null, result);
return;
}
Proposed Fix
Update the currency_conversion.json
file by adding the correct conversion rate for GBP. Based on the other conversion rates in the file, the GBP should have a valid numeric value.
{
"EUR": "1.0",
"USD": "1.1305",
"JPY": "126.40",
"BGN": "1.9558",
"CZK": "25.592",
"DKK": "7.4609",
- "GBP": "",
+ "GBP": "0.8508",
"HUF": "315.51",
"PLN": "4.2996",
"RON": "4.7463",
"SEK": "10.5375",
"CHF": "1.1360",
"ISK": "136.80",
"NOK": "9.8040",
"HRK": "7.4210",
"RUB": "74.4208",
"TRY": "6.1247",
"AUD": "1.6072",
"BRL": "4.2682",
"CAD": "1.5128",
"CNY": "7.5857",
"HKD": "8.8743",
"IDR": "15999.40",
"ILS": "4.0875",
"INR": "79.4320",
"KRW": "1275.05",
"MXN": "21.7999",
"MYR": "4.6289",
"NZD": "1.6679",
"PHP": "59.083",
"SGD": "1.5349",
"THB": "36.012",
"ZAR": "16.0583"
}
The value 0.8508 is a realistic EUR to GBP conversion rate (based on historical data from around the time the other rates were defined). This will fix the GBP currency conversion issues.
Impact
- This fix will allow users to properly convert prices to GBP currency
- It will eliminate the error logs and Slack notifications related to GBP conversions
- The e-commerce platform will provide a better user experience for customers wanting to see prices in GBP