From a1a1081b4251550262579826fbd44bc7251521f5 Mon Sep 17 00:00:00 2001 From: shayan khaleghparast Date: Mon, 18 Nov 2024 12:11:46 +0800 Subject: [PATCH] chore: set fallback values as empty string in all cases --- src/utils/__test__/country.utils.spec.ts | 2 +- src/utils/country.utils.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/__test__/country.utils.spec.ts b/src/utils/__test__/country.utils.spec.ts index a4fef83..99389ef 100644 --- a/src/utils/__test__/country.utils.spec.ts +++ b/src/utils/__test__/country.utils.spec.ts @@ -39,6 +39,6 @@ describe("getCountry", () => { (Cookies.get as Mock).mockReturnValue(JSON.stringify({})); const { getCountry } = await import("../country.utils"); const result = await getCountry(); - expect(result).toBe(""); + expect(result).toBe("nodata"); }); }); diff --git a/src/utils/country.utils.ts b/src/utils/country.utils.ts index ec2f7bb..ddc1e9a 100644 --- a/src/utils/country.utils.ts +++ b/src/utils/country.utils.ts @@ -27,15 +27,15 @@ export const getCountry = async (): Promise => { countryPromise = (async () => { try { const response = await fetch(cloudflareTrace).catch(() => null); - if (!response) return cookieCountry || "nodata"; + if (!response) return cookieCountry || ""; const text = await response.text().catch(() => ""); - if (!text) return cookieCountry || "nodata"; + if (!text) return cookieCountry || ""; const data: TraceData = Object.fromEntries(text.split("\n").map((v) => v.split("=", 2))); - return data.loc?.toLowerCase() || cookieCountry || "nodata"; + return data.loc?.toLowerCase() || cookieCountry || ""; } catch { - return cookieCountry || "error"; + return cookieCountry || ""; } })();