Chore: Refactor error when retrieving the plugin manifest key (#72492)

This commit is contained in:
Andres Martinez Gotor 2023-07-28 10:22:21 +02:00 committed by GitHub
parent 3a84db0012
commit a331c892a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io"
"net" "net"
"net/http" "net/http"
"net/url" "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 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 { if len(data.Items) == 0 {
return errors.New("missing public key") return errors.New("missing public key")
} }