minor cleanup

This commit is contained in:
2026-05-07 16:26:03 +02:00
parent 978b7a319f
commit f06a2d82e9
3 changed files with 44 additions and 30 deletions

View File

@@ -90,11 +90,12 @@ func (c *SpotifyClient) GetPlaylist(playlistID string) (*SpotifyPlaylist, error)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("API error (%d): %s", resp.StatusCode, body)
return nil, fmt.Errorf("status code: %d: %s", resp.StatusCode, body)
}
var playlist SpotifyPlaylist
@@ -115,6 +116,7 @@ func (c *SpotifyClient) renewToken() error {
if err != nil {
return err
}
req.Header.Set("Authorization", "Basic "+creds)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
@@ -122,11 +124,12 @@ func (c *SpotifyClient) renewToken() error {
if err != nil {
return err
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("auth failed (%d): %s", resp.StatusCode, body)
return fmt.Errorf("auth failed: %d: %s", resp.StatusCode, body)
}
var token spotifyTokenResponse
@@ -158,5 +161,6 @@ func (c *SpotifyClient) doOnce(req *http.Request) (*http.Response, error) {
c.mu.Lock()
req.Header.Set("Authorization", "Bearer "+c.token)
c.mu.Unlock()
return c.httpClient.Do(req)
}