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"
"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