diff --git a/vault/http.go b/vault/http.go index a8fe4380528c07d39169594b57942f3cb4c37c70..6dee93e46afd31de8ab58964abeaf6de9e930311 100644 --- a/vault/http.go +++ b/vault/http.go @@ -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