Skip to content

Commit

Permalink
check errors when creating request
Browse files Browse the repository at this point in the history
related #494
  • Loading branch information
sentriz committed Apr 7, 2024
1 parent 8a0fa05 commit cc4c57b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lastfm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ func (c *Client) GetCurrentUser(user *db.User) (User, error) {
}

func (c *Client) makeRequest(method string, params url.Values) (LastFM, error) {
req, _ := http.NewRequest(method, BaseURL, nil)
req, err := http.NewRequest(method, BaseURL, nil)
if err != nil {
return LastFM{}, fmt.Errorf("create request: %w", err)
}

req.URL.RawQuery = params.Encode()

resp, err := c.httpClient.Do(req)
Expand Down
6 changes: 5 additions & 1 deletion listenbrainz/listenbrainz.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func (c *Client) Scrobble(user db.User, track scrobble.Track, stamp time.Time, s
submitURL := fmt.Sprintf("%s%s", user.ListenBrainzURL, submitPath)
authHeader := fmt.Sprintf("Token %s", user.ListenBrainzToken)

req, _ := http.NewRequest(http.MethodPost, submitURL, &payloadBuf)
req, err := http.NewRequest(http.MethodPost, submitURL, &payloadBuf)
if err != nil {
return fmt.Errorf("create submit request: %w", err)
}

req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", authHeader)

Expand Down

0 comments on commit cc4c57b

Please sign in to comment.