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 }