check errors when creating request

related #494
This commit is contained in:
sentriz
2024-04-07 17:53:12 +01:00
parent 8a0fa05c7c
commit cc4c57be98
2 changed files with 10 additions and 2 deletions

View File

@@ -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)

View File

@@ -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)