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:
+7
-1
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user