mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
Chore: Refactor error when retrieving the plugin manifest key (#72492)
This commit is contained in:
parent
3a84db0012
commit
a331c892a0
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -134,10 +135,20 @@ func (kr *KeyRetriever) downloadKeys(ctx context.Context) error {
|
||||
}
|
||||
}()
|
||||
|
||||
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(body, &data); err != nil {
|
||||
kr.log.Debug("error unmarshalling response body", "error", err, "body", string(body))
|
||||
return fmt.Errorf("error unmarshalling response body: %w", err)
|
||||
}
|
||||
|
||||
if len(data.Items) == 0 {
|
||||
return errors.New("missing public key")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user