From bcef1a1ccef2b6e47763faf1108f116c13806536 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 3 Aug 2017 18:18:05 +0200 Subject: [PATCH] Return 404 on not existent secret Signed-off-by: Knut Ahlers --- api.go | 6 +++++- storage_redis.go | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/api.go b/api.go index c3596ad..887e981 100644 --- a/api.go +++ b/api.go @@ -60,7 +60,11 @@ func (a apiServer) handleRead(res http.ResponseWriter, r *http.Request) { secret, err := a.store.ReadAndDestroy(id) if err != nil { - a.jsonResponse(res, http.StatusInternalServerError, map[string]interface{}{ + status := http.StatusInternalServerError + if err == errSecretNotFound { + status = http.StatusNotFound + } + a.jsonResponse(res, status, map[string]interface{}{ "success": false, "error": err.Error(), }) diff --git a/storage_redis.go b/storage_redis.go index 4d2610e..b3ef77d 100644 --- a/storage_redis.go +++ b/storage_redis.go @@ -49,6 +49,10 @@ func (s storageRedis) ReadAndDestroy(id string) (string, error) { return "", err } + if secret == nil { + return "", errSecretNotFound + } + _, err = s.conn.HDel(s.redisKey(), id) return string(secret), err }