Add error handling to spotify client but bad
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user