From e564c285543b9d1e8f5efb6c788b96b9a0fbbe78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Hedenstro=CC=88m?= <erik@hedenstroem.com> Date: Sun, 18 Dec 2016 14:10:06 +0100 Subject: [PATCH] Added better error messages --- vault/http.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/vault/http.go b/vault/http.go index a8fe438..6dee93e 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 -- GitLab