overleaf/overleaf · error · InvalidError

Invalid country

Error message

Invalid country

What it means

While building Recurly billing/purchase XML, this code validates the address from subscriptionDetails and throws Errors.InvalidError with message 'Invalid country' when the address is missing entirely or address.country is empty — Recurly requires a valid country on billing addresses.

Source

Thrown at services/web/app/src/Features/Subscription/RecurlyWrapper.mjs:952

    })
  }
  if (subscriptionDetails.ITMReferrer) {
    customFields.push({
      name: 'itm_referrer',
      value: subscriptionDetails.ITMReferrer,
    })
  }
  return { custom_field: customFields }
}

function getAddressFromSubscriptionDetails(
  subscriptionDetails,
  includeCompanyInfo
) {
  const { address } = subscriptionDetails

  if (!address || !address.country) {
    throw new Errors.InvalidError({
      message: 'Invalid country',
      info: {
        public: {
          message: 'Invalid country',
        },
      },
    })
  }

  const addressObject = {
    address1: address.address1,
    address2: address.address2 || '',
    city: address.city || '',
    state: address.state || '',
    zip: address.zip || '',
    country: address.country,
  }

View on GitHub (pinned to 28ad3b03b7)

Solutions

  1. Validate that subscriptionDetails.address and address.country are present before calling the Recurly wrapper
  2. Add a required country field / client-side validation in the address form
  3. Default the country from user geolocation or IP when missing, with user confirmation
  4. Catch Errors.InvalidError and show 'Please provide a country' to the user

Example fix

// before
await RecurlyWrapper.purchase(subscriptionDetails)
// after
if (!subscriptionDetails.address?.country) {
  throw new Error('country is required')
}
await RecurlyWrapper.purchase(subscriptionDetails)
Defensive patterns

Strategy: validation

Validate before calling

if (!subscriptionDetails?.address?.country) {
  throw new Error('country is required before calling Recurly')
}

Type guard

function hasValidCountry(details) {
  return (
    typeof details?.address?.country === 'string' &&
    details.address.country.length > 0
  )
}

Try / catch

try {
  await RecurlyWrapper.purchase(subscriptionDetails)
} catch (err) {
  if (err instanceof Errors.InvalidError) {
    return { error: 'invalid-address', field: 'country' }
  }
  throw err
}

Prevention

When it happens

Trigger: Calling a RecurlyWrapper purchase/subscription function with subscriptionDetails whose address is undefined, or whose address.country is null/empty string (e.g. a form submitted without selecting a country).

Common situations: Signup forms with optional country fields; IP-geolocation-based country inference failing and leaving country blank; users with addresses saved before country became required; regional deployments not enforcing country validation client-side.

Related errors


AI-assisted analysis of overleaf/overleaf@28ad3b03b7 (2026-09-03). Data as JSON: /api/errors/7cafe913d1423463. Report an issue: GitHub.