mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-31 11:57:50 +01:00
Fix 401 error
This commit is contained in:
@@ -82,22 +82,19 @@ export async function regenerateTokens(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function RequestWrapper<T = never>(url: string): Promise<AxiosResponse<T> | undefined> {
|
async function RequestWrapper<T = never>(url: string): Promise<AxiosResponse<T> | undefined> {
|
||||||
let request
|
|
||||||
const options: AxiosRequestConfig = {
|
const options: AxiosRequestConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${(await getSpotifyAccount()).access_token}`,
|
Authorization: `Bearer ${(await getSpotifyAccount()).access_token}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
request = await axios.get<T>(url, options)
|
return await axios.get<T>(url, options)
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
await regenerateTokens()
|
await regenerateTokens()
|
||||||
request = await axios.get<T>(url, options)
|
return RequestWrapper<T>(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.status === 200)
|
|
||||||
return request
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCurrentPlayingFromCache(): Promise<InternalPlayerResponse> {
|
export async function getCurrentPlayingFromCache(): Promise<InternalPlayerResponse> {
|
||||||
|
|||||||
Reference in New Issue
Block a user