Skip to content

Commit

Permalink
chore: set fallback values as empty string in all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
shayan-deriv committed Nov 18, 2024
1 parent e6e3921 commit a1a1081
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/utils/__test__/country.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
8 changes: 4 additions & 4 deletions src/utils/country.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export const getCountry = async (): Promise<string> => {
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 || "";
}
})();

Expand Down

0 comments on commit a1a1081

Please sign in to comment.