log bad scrobble responses

related #219
This commit is contained in:
sentriz
2022-05-15 15:01:58 +01:00
parent 182c96e966
commit 4fce8e67ce
2 changed files with 8 additions and 3 deletions

View File

@@ -6,7 +6,9 @@ import (
"encoding/xml" "encoding/xml"
"errors" "errors"
"fmt" "fmt"
"log"
"net/http" "net/http"
"net/http/httputil"
"net/url" "net/url"
"sort" "sort"
"strconv" "strconv"
@@ -153,9 +155,13 @@ func makeRequest(method string, params url.Values) (LastFM, error) {
decoder := xml.NewDecoder(resp.Body) decoder := xml.NewDecoder(resp.Body)
lastfm := LastFM{} lastfm := LastFM{}
if err = decoder.Decode(&lastfm); err != nil { 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) return LastFM{}, fmt.Errorf("decoding: %w", err)
} }
if lastfm.Error.Code != 0 { 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{}, fmt.Errorf("%v: %w", lastfm.Error.Value, ErrLastFM)
} }
return lastfm, nil return lastfm, nil

View File

@@ -92,13 +92,12 @@ func (s *Scrobbler) Scrobble(user *db.User, track *db.Track, stamp time.Time, su
} }
defer resp.Body.Close() defer resp.Body.Close()
respBytes, _ := httputil.DumpResponse(resp, true)
switch { switch {
case resp.StatusCode == http.StatusUnauthorized: case resp.StatusCode == http.StatusUnauthorized:
return fmt.Errorf("unathorized: %w", ErrListenBrainz) return fmt.Errorf("unathorized: %w", ErrListenBrainz)
case resp.StatusCode >= 400: case resp.StatusCode >= 400:
log.Println("received listenbrainz response") respBytes, _ := httputil.DumpResponse(resp, true)
log.Println(string(respBytes)) log.Printf("received bad listenbrainz response:\n%s", string(respBytes))
return fmt.Errorf(">= 400: %d: %w", resp.StatusCode, ErrListenBrainz) return fmt.Errorf(">= 400: %d: %w", resp.StatusCode, ErrListenBrainz)
} }
return nil return nil