wrap auth util functions in try blocks

This commit is contained in:
Nathaniel Tampus
2023-03-06 11:43:34 +08:00
parent dd1166dc42
commit 4e17eadb7a

View File

@@ -2,6 +2,7 @@ import type { User } from "@chessu/types";
import { API_URL } from "@/config";
export const fetchSession = async () => {
try {
const res = await fetch(`${API_URL}/v1/auth`, {
credentials: "include"
});
@@ -10,9 +11,13 @@ export const fetchSession = async () => {
const user: User = await res.json();
return user;
}
} catch (err) {
console.error(err);
}
};
export const setGuestSession = async (name: string) => {
try {
const res = await fetch(`${API_URL}/v1/auth/guest`, {
method: "POST",
credentials: "include",
@@ -25,4 +30,7 @@ export const setGuestSession = async (name: string) => {
const user: User = await res.json();
return user;
}
} catch (err) {
console.error(err);
}
};