trial log, profile fixes
This commit is contained in:
+10
-7
@@ -7,17 +7,13 @@ export const fetchProfile = async () => {
|
||||
if (!token) throw new Error("No token found");
|
||||
|
||||
const res = await fetch(`${API_BASE}/me`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error("Failed to fetch profile");
|
||||
return res.json();
|
||||
};
|
||||
|
||||
// Существующий код...
|
||||
|
||||
export const submitHackResult = async (score: number) => {
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
if (!token) throw new Error("No token found");
|
||||
@@ -35,13 +31,17 @@ export const submitHackResult = async (score: number) => {
|
||||
return res.json();
|
||||
};
|
||||
|
||||
// 🔥 ИСПРАВЛЕНО: Правильный парсинг ошибки Триала
|
||||
export const activateTrial = async () => {
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
const res = await fetch(`${API_BASE}/trial`, {
|
||||
method: "POST",
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
if (!res.ok) {
|
||||
const errData = await res.json().catch(() => ({}));
|
||||
throw new Error(errData.error || res.statusText || "Activation failed");
|
||||
}
|
||||
return res.json();
|
||||
};
|
||||
|
||||
@@ -55,6 +55,9 @@ export const buySubscription = async (plan: string) => {
|
||||
},
|
||||
body: JSON.stringify({ plan }),
|
||||
});
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
if (!res.ok) {
|
||||
const errData = await res.json().catch(() => ({}));
|
||||
throw new Error(errData.error || res.statusText || "Purchase failed");
|
||||
}
|
||||
return res.json();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user