mirror of
https://github.com/Luzifer/ots.git
synced 2024-12-19 20:44:35 -05:00
Return 404 on not existent secret
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
9c81f9223f
commit
bcef1a1cce
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)
|
secret, err := a.store.ReadAndDestroy(id)
|
||||||
if err != nil {
|
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,
|
"success": false,
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
|
@ -49,6 +49,10 @@ func (s storageRedis) ReadAndDestroy(id string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if secret == nil {
|
||||||
|
return "", errSecretNotFound
|
||||||
|
}
|
||||||
|
|
||||||
_, err = s.conn.HDel(s.redisKey(), id)
|
_, err = s.conn.HDel(s.redisKey(), id)
|
||||||
return string(secret), err
|
return string(secret), err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user