Skip to content

Commit

Permalink
log listenbrainz scrobble response
Browse files Browse the repository at this point in the history
  • Loading branch information
sentriz committed Nov 6, 2021
1 parent 98cab93 commit 4781a74
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/scrobble/listenbrainz/listenbrainz.go
Expand Up @@ -5,7 +5,9 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"net/http/httputil"
"time"

"go.senan.xyz/gonic/server/db"
Expand Down Expand Up @@ -86,11 +88,14 @@ func (s *Scrobbler) Scrobble(user *db.User, track *db.Track, stamp time.Time, su
return fmt.Errorf("http post: %w", err)
}
defer resp.Body.Close()
respBytes, _ := httputil.DumpResponse(resp, true)
switch {
case resp.StatusCode == http.StatusUnauthorized:
return fmt.Errorf("unathorized: %w", ErrListenBrainz)
case resp.StatusCode >= 200:
return fmt.Errorf("non >= 400: %d: %w", resp.StatusCode, ErrListenBrainz)
case resp.StatusCode >= 400:
log.Println("received listenbrainz response")
log.Println(string(respBytes))
return fmt.Errorf(">= 400: %d: %w", resp.StatusCode, ErrListenBrainz)
}
return nil
}
Expand Down

0 comments on commit 4781a74

Please sign in to comment.