mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Small improvements to grafana-cli (#16670)
* Small improvements * Better error handling
This commit is contained in:
@@ -21,6 +21,7 @@ var (
|
||||
IoHelper m.IoUtil = IoUtilImp{}
|
||||
HttpClient http.Client
|
||||
grafanaVersion string
|
||||
NotFoundError = errors.New("404 not found error")
|
||||
)
|
||||
|
||||
func Init(version string, skipTLSVerify bool) {
|
||||
@@ -126,10 +127,14 @@ func RemoveInstalledPlugin(pluginPath, pluginName string) error {
|
||||
}
|
||||
|
||||
func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) {
|
||||
logger.Debugf("getting plugin metadata from: %v pluginId: %v \n", repoUrl, pluginId)
|
||||
body, err := sendRequest(repoUrl, "repo", pluginId)
|
||||
|
||||
if err != nil {
|
||||
logger.Info("Failed to send request", "error", err)
|
||||
logger.Info("Failed to send request: ", err)
|
||||
if err == NotFoundError {
|
||||
return m.Plugin{}, fmt.Errorf("Failed to find requested plugin, check if the plugin_id is correct. error: %v", err)
|
||||
}
|
||||
return m.Plugin{}, fmt.Errorf("Failed to send request. error: %v", err)
|
||||
}
|
||||
|
||||
@@ -169,6 +174,9 @@ func sendRequest(repoUrl string, subPaths ...string) ([]byte, error) {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
if res.StatusCode == 404 {
|
||||
return []byte{}, NotFoundError
|
||||
}
|
||||
if res.StatusCode/100 != 2 {
|
||||
return []byte{}, fmt.Errorf("Api returned invalid status: %s", res.Status)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user