Skip to content

Currency conversion failure due to empty GBP exchange rate in currency_conversion.json #103

Description

@osw282

Issue Description

The currencyservice is encountering recurring conversion errors that result in zero-amount calculations, causing the service to fall back to the original currency. This is happening consistently in the production environment.

Error Analysis

From the pod logs, I can see repeated instances of:

"Currency conversion resulted in zero amount, switching back to original currency"

Root Cause

After examining the source code in src/currencyservice/server.js and the currency data in src/currencyservice/data/currency_conversion.json, I've identified the issue:

The GBP (British Pound) exchange rate is set to an empty string in the currency_conversion.json file:

{
  "EUR": "1.0",
  "USD": "1.1305",
  "JPY": "126.40",
  ...
  "GBP": "",  // <- This is the problem
  ...
}

Technical Details

In the convert function in server.js, the conversion logic performs:

  1. Convert from source currency to EUR: from.units / data[from.currency_code]
  2. Convert from EUR to target currency: euros.units * data[request.to_code]

When the GBP rate is an empty string, JavaScript coerces it to 0, causing:

  • Division by 0 when converting FROM GBP (results in Infinity)
  • Multiplication by 0 when converting TO GBP (results in 0)

This leads to zero amounts after the Math.floor() operations, triggering the error handling logic.

Recommended Fix

Replace the empty GBP exchange rate with the correct value. Based on typical EUR-GBP rates, it should be approximately "0.85" to "0.90".

Proposed change in src/currencyservice/data/currency_conversion.json:

{
  "EUR": "1.0",
  "USD": "1.1305",
  "JPY": "126.40",
  "BGN": "1.9558",
  "CZK": "25.592",
  "DKK": "7.4609",
  "GBP": "0.8750",  // Updated with proper exchange rate
  "HUF": "315.51",
  // ... rest of the currencies
}

Additional Recommendations

  1. Add input validation in the convert function to check for invalid exchange rates (empty strings, null, zero values)
  2. Implement better error handling to log the specific currencies involved in failed conversions
  3. Consider adding unit tests to catch such data integrity issues
  4. Set up monitoring alerts for zero-amount conversions to catch similar issues quickly

Impact

This issue affects any currency conversion involving GBP, causing:

  • Failed transactions when users try to view prices in British Pounds
  • Fallback to original currencies, leading to poor user experience
  • Increased error logging and unnecessary Slack notifications

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions