Add error handling to spotify client but bad

This commit is contained in:
Pablu23
2025-09-02 16:25:15 +02:00
parent 86333902d4
commit 680526903b
2 changed files with 15 additions and 2 deletions

View File

@@ -2,10 +2,17 @@ export const getJson = async (accessToken: string, subUri: string) => {
const baseUrl = new URL("https://api.spotify.com/");
const requestUrl = new URL(subUri, baseUrl);
return await fetch(requestUrl, {
const response = await fetch(requestUrl, {
method: 'GET',
headers: {
"Authorization": `Bearer ${accessToken}`
}
})
if (!response.ok) {
console.log(response)
return null
}
return response
}

View File

@@ -1,5 +1,11 @@
import { redirect } from "@sveltejs/kit";
import { getJson } from "./base"
export const getCurrentUserProfile = async (accessToken: string) => {
return await (await getJson(accessToken, "/v1/me")).json()
const response = await getJson(accessToken, "/v1/me");
if (!response) {
redirect(307, "/error")
}
return await response.json()
}