diff options
| author | Bobby <[email protected]> | 2025-11-05 22:19:55 +0530 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-05 22:19:55 +0530 |
| commit | 3a443df693af822cf2483f4333b8b4f5e0f9a6df (patch) | |
| tree | 59e38b3a67336dbb8f72fda3790cf38214b5c95d | |
| parent | 0f1e51d4d77ed5ceda277eff8080e1455243f8a6 (diff) | |
| download | unwordled-3a443df693af822cf2483f4333b8b4f5e0f9a6df.tar.xz unwordled-3a443df693af822cf2483f4333b8b4f5e0f9a6df.zip | |
Updated fetchWordleAnswer function to use a proxy for API requests and added error handling.
| -rw-r--r-- | script.js | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -206,10 +206,30 @@ document.addEventListener('click', closeAllDropdowns); */ async function fetchWordleAnswer(date) { const apiDate = formatDateForAPI(date); - const url = `https://www.nytimes.com/svc/wordle/v2/${apiDate}.json`; - const response = await fetch(url); - if (!response.ok) throw new Error('Answer not available for this date'); - return await response.json(); + const proxyBase = "https://wordle-proxy.bobbyskhs.workers.dev"; + + try { + const response = await fetch(`${proxyBase}/?date=${apiDate}`, { + headers: { + "Accept": "application/json", + }, + cache: "no-cache", + }); + + if (!response.ok) { + throw new Error(`Answer not available for ${apiDate}`); + } + + const data = await response.json(); + if (!data || !data.solution) { + throw new Error("Invalid data received from proxy"); + } + + return data; + } catch (error) { + console.error("Wordle fetch error:", error); + throw new Error("Failed to fetch Wordle data"); + } } /** |
