Skip to content

Commit

Permalink
Merge pull request #225 from aws-geospatial/fetch-country-code
Browse files Browse the repository at this point in the history
[Bug] Fetch country code
  • Loading branch information
wadhawh authored Jul 27, 2024
2 parents 784664d + e7f2f4b commit 3931721
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/constants/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const appConfig = {
CF_TEMPLATE: getEnv("VITE_AWS_CF_TEMPLATE"),
APPLE_APP_STORE_LINK: getEnv("VITE_APPLE_APP_STORE_LINK"),
GOOGLE_PLAY_STORE_LINK: getEnv("VITE_GOOGLE_PLAY_STORE_LINK"),
COUNTRY_EVALUATION_URL: import.meta.env.DEV ? "/doNotDelete.txt" : "assets/doNotDelete.txt",
COUNTRY_EVALUATION_URL: "/doNotDelete.txt",
APP_VERSION: getEnv("VITE_APP_VERSION"),
NL_BASE_URL: getEnv("VITE_NL_BASE_URL"),
NL_API_KEY: getEnv("VITE_NL_API_KEY"),
Expand Down
3 changes: 3 additions & 0 deletions src/utils/analyticsUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. */
/* SPDX-License-Identifier: MIT-0 */

import {
Event,
GetEndpointCommand,
Expand Down
11 changes: 10 additions & 1 deletion src/utils/countryUtil.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. */
/* SPDX-License-Identifier: MIT-0 */

import { appConfig } from "@demo/core/constants";

import sleep from "./sleep";

let failCount = 0;
let countryCode = "";

const {
ENV: { COUNTRY_EVALUATION_URL }
} = appConfig;

export const getCountryCode: () => Promise<string | undefined> = async () => {
try {
if (countryCode) {
return countryCode === "Unknown" ? undefined : countryCode;
}

const response = await fetch(COUNTRY_EVALUATION_URL);
const country = response.headers.get("x-country");
countryCode = country || "Unknown";

failCount = 0;

Expand All @@ -22,7 +31,7 @@ export const getCountryCode: () => Promise<string | undefined> = async () => {
}
} catch (error) {
failCount++;
console.log("error: ", error);
console.error("error: ", error);

// try three times before failing
if (failCount === 3) {
Expand Down

0 comments on commit 3931721

Please sign in to comment.