Skip to content

Commit

Permalink
log bad scrobble responses
Browse files Browse the repository at this point in the history
related #219
  • Loading branch information
sentriz committed May 15, 2022
1 parent 182c96e commit 4fce8e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 6 additions & 0 deletions scrobble/lastfm/lastfm.go
Expand Up @@ -6,7 +6,9 @@ import (
"encoding/xml"
"errors"
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
"sort"
"strconv"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions scrobble/listenbrainz/listenbrainz.go
Expand Up @@ -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
Expand Down

0 comments on commit 4fce8e6

Please sign in to comment.