diff --git a/fetch.go b/fetch.go index 0ffc292..7795531 100644 --- a/fetch.go +++ b/fetch.go @@ -123,6 +123,10 @@ func (c *Client[T]) GetOrFetch(ctx context.Context, key string, fetchFn FetchFn[ // T - The type stored in the cache. func GetOrFetch[V, T any](ctx context.Context, c *Client[T], key string, fetchFn FetchFn[V]) (V, error) { res, err := getFetch[V, T](ctx, c, key, fetchFn) + if err != nil { + var zero V + return zero, err + } return unwrap[V](res, err) } @@ -227,5 +231,9 @@ func (c *Client[T]) GetOrFetchBatch(ctx context.Context, ids []string, keyFn Key func GetOrFetchBatch[V, T any](ctx context.Context, c *Client[T], ids []string, keyFn KeyFn, fetchFn BatchFetchFn[V]) (map[string]V, error) { res, err := getFetchBatch[V, T](ctx, c, ids, keyFn, fetchFn) + if err != nil { + var zero map[string]V + return zero, err + } return unwrapBatch[V](res, err) }