chore(server): add more info to scrobble errors logs (#3889)
* chore(server): add more info to scrobble errors Signed-off-by: Deluan <deluan@navidrome.org> * chore(server): add more info to scrobble errors Signed-off-by: Deluan <deluan@navidrome.org> * chore(server): add more info to scrobble errors Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Vendored
+3
-1
@@ -49,16 +49,18 @@ func (c *HTTPClient) Do(req *http.Request) (*http.Response, error) {
|
||||
cached = false
|
||||
req, err := c.deserializeReq(key)
|
||||
if err != nil {
|
||||
log.Trace(req.Context(), "CachedHTTPClient.Do", "key", key, err)
|
||||
return "", 0, err
|
||||
}
|
||||
resp, err := c.hc.Do(req)
|
||||
if err != nil {
|
||||
log.Trace(req.Context(), "CachedHTTPClient.Do", "req", req, err)
|
||||
return "", 0, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return c.serializeResponse(resp), c.ttl, nil
|
||||
})
|
||||
log.Trace(req.Context(), "CachedHTTPClient.Do", "key", key, "cached", cached, "elapsed", time.Since(start))
|
||||
log.Trace(req.Context(), "CachedHTTPClient.Do", "key", key, "cached", cached, "elapsed", time.Since(start), err)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Vendored
+8
-1
@@ -2,6 +2,7 @@ package cache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@@ -74,10 +75,13 @@ func (c *simpleCache[K, V]) Get(key K) (V, error) {
|
||||
}
|
||||
|
||||
func (c *simpleCache[K, V]) GetWithLoader(key K, loader func(key K) (V, time.Duration, error)) (V, error) {
|
||||
var err error
|
||||
loaderWrapper := ttlcache.LoaderFunc[K, V](
|
||||
func(t *ttlcache.Cache[K, V], key K) *ttlcache.Item[K, V] {
|
||||
c.evictExpired()
|
||||
value, ttl, err := loader(key)
|
||||
var value V
|
||||
var ttl time.Duration
|
||||
value, ttl, err = loader(key)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -87,6 +91,9 @@ func (c *simpleCache[K, V]) GetWithLoader(key K, loader func(key K) (V, time.Dur
|
||||
item := c.data.Get(key, ttlcache.WithLoader[K, V](loaderWrapper))
|
||||
if item == nil {
|
||||
var zero V
|
||||
if err != nil {
|
||||
return zero, fmt.Errorf("cache error: loader returned %w", err)
|
||||
}
|
||||
return zero, errors.New("item not found")
|
||||
}
|
||||
return item.Value(), nil
|
||||
|
||||
Reference in New Issue
Block a user