Skip to content
Snippets Groups Projects
Commit e564c285 authored by Erik Hedenström's avatar Erik Hedenström
Browse files

Added better error messages

parent 43eaa3f4
Branches
Tags 0.3.0
No related merge requests found
Pipeline #
......@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"github.com/spf13/viper"
......@@ -24,15 +25,21 @@ func GetSecret(path string) (data map[string]interface{}, err error) {
return
}
if res.StatusCode == http.StatusOK {
switch res.StatusCode {
case http.StatusOK:
var parsed map[string]interface{}
defer res.Body.Close()
json.NewDecoder(res.Body).Decode(&parsed)
data = parsed["data"].(map[string]interface{})
}
if res.StatusCode == http.StatusNotFound {
case http.StatusNoContent:
data = make(map[string]interface{})
case http.StatusNotFound:
err = errors.New(path + " was not found")
default:
var parsed map[string]interface{}
defer res.Body.Close()
json.NewDecoder(res.Body).Decode(&parsed)
err = errors.New(fmt.Sprint(parsed["errors"]))
}
return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment