@@ -6,7 +6,9 @@ import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -153,9 +155,13 @@ func makeRequest(method string, params url.Values) (LastFM, error) {
|
||||
decoder := xml.NewDecoder(resp.Body)
|
||||
lastfm := LastFM{}
|
||||
if err = decoder.Decode(&lastfm); err != nil {
|
||||
respBytes, _ := httputil.DumpResponse(resp, true)
|
||||
log.Printf("received bad lastfm response:\n%s", string(respBytes))
|
||||
return LastFM{}, fmt.Errorf("decoding: %w", err)
|
||||
}
|
||||
if lastfm.Error.Code != 0 {
|
||||
respBytes, _ := httputil.DumpResponse(resp, true)
|
||||
log.Printf("received bad lastfm response:\n%s", string(respBytes))
|
||||
return LastFM{}, fmt.Errorf("%v: %w", lastfm.Error.Value, ErrLastFM)
|
||||
}
|
||||
return lastfm, nil
|
||||
|
||||
@@ -92,13 +92,12 @@ func (s *Scrobbler) Scrobble(user *db.User, track *db.Track, stamp time.Time, su
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBytes, _ := httputil.DumpResponse(resp, true)
|
||||
switch {
|
||||
case resp.StatusCode == http.StatusUnauthorized:
|
||||
return fmt.Errorf("unathorized: %w", ErrListenBrainz)
|
||||
case resp.StatusCode >= 400:
|
||||
log.Println("received listenbrainz response")
|
||||
log.Println(string(respBytes))
|
||||
respBytes, _ := httputil.DumpResponse(resp, true)
|
||||
log.Printf("received bad listenbrainz response:\n%s", string(respBytes))
|
||||
return fmt.Errorf(">= 400: %d: %w", resp.StatusCode, ErrListenBrainz)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user