Return 404 on not existent secret
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
9c81f9223f
commit
bcef1a1cce
2 changed files with 9 additions and 1 deletions
6
api.go
6
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(),
|
||||
})
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue