Return 404 on not existent secret

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2017-08-03 18:18:05 +02:00
parent 9c81f9223f
commit bcef1a1cce
No known key found for this signature in database
GPG key ID: DC2729FDD34BE99E
2 changed files with 9 additions and 1 deletions

6
api.go
View file

@ -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(),
})