Return 404 when deleting non-existing API key (#33346)

The server needs to return a HTTP 404 (Not Found) when an API key that does not exist is deleted.
This commit is contained in:
Christian Haudum
2021-04-28 13:30:09 +02:00
committed by GitHub
parent 1336a57e99
commit 076e2ce06a
4 changed files with 43 additions and 14 deletions
+7 -1
View File
@@ -43,7 +43,13 @@ func DeleteAPIKey(c *models.ReqContext) response.Response {
err := bus.Dispatch(cmd)
if err != nil {
return response.Error(500, "Failed to delete API key", err)
var status int
if errors.Is(err, models.ErrApiKeyNotFound) {
status = 404
} else {
status = 500
}
return response.Error(status, "Failed to delete API key", err)
}
return response.Success("API key deleted")