Distinguish Spotify playlist restrictions from missing OAuth scopes
This commit is contained in:
+11
-1
@@ -106,7 +106,17 @@ export async function spotifyApi(path, { method = 'GET', body, signal } = {}) {
|
||||
headers: { Authorization: `Bearer ${token}`, ...(body ? { 'Content-Type': 'application/json' } : {}) },
|
||||
...(body ? { body: JSON.stringify(body) } : {}),
|
||||
});
|
||||
if (response.status === 403) return { error: 'spotify_permission_required', hint: 'Переподключи Spotify в пульте, чтобы разрешить работу с плейлистами.' };
|
||||
if (response.status === 403) {
|
||||
const failure = await response.json().catch(() => null);
|
||||
const reason = `${response.headers.get('www-authenticate') || ''} ${failure?.error?.message || ''}`;
|
||||
if (/insufficient[_ ](?:client )?scope/i.test(reason)) {
|
||||
return { error: 'spotify_permission_required', hint: 'Переподключи Spotify в пульте, чтобы разрешить работу с плейлистами.' };
|
||||
}
|
||||
if (path.startsWith('playlists/')) {
|
||||
return { error: 'spotify_playlist_access_denied', hint: 'Spotify разрешает читать и менять состав плейлиста его владельцу и соавторам.' };
|
||||
}
|
||||
return { error: 'spotify_access_denied' };
|
||||
}
|
||||
if (!response.ok) return { error: 'spotify_request_failed' };
|
||||
return response.status === 204 ? { ok: true } : response.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user