forked from NilsDelage/countdown-page
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cb0fc9
commit 408df81
Showing
2 changed files
with
56 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
export async function fetchToken(reconnect: boolean) { | ||
const response = await fetch( | ||
`https://play.metacube.games/api/set-cookie?reconnect=${reconnect}`, | ||
{ | ||
method: "GET", | ||
credentials: "include", | ||
export async function fetchToken(reconnect: boolean): Promise<string> { | ||
try { | ||
const response = await fetch( | ||
`https://play.metacube.games/api/set-cookie?reconnect=${reconnect}`, | ||
{ | ||
method: "GET", | ||
credentials: "include", // Ensures cookies are included | ||
} | ||
); | ||
|
||
if (!response.ok) { | ||
// Handle specific HTTP error status if needed | ||
throw new Error( | ||
`Failed to set token cookie: ${response.status} ${response.statusText}` | ||
); | ||
} | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error("Failed to set token cookie"); | ||
} | ||
// Check if the response contains JSON | ||
let data; | ||
try { | ||
data = await response.json(); | ||
} catch (jsonError) { | ||
throw new Error("Failed to parse JSON response"); | ||
} | ||
|
||
const data = await response.json(); | ||
return data.message; | ||
return data.message || "Token cookie set successfully"; | ||
} catch (error: any) { | ||
console.error("Error in fetchToken:", error.message); | ||
throw new Error( | ||
error.message || "Unknown error occurred while fetching token" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters