Skip to content

Commit 3785221

Browse files
author
Gusted
committed
Fix DELETE request for non-existent public key (go-gitea#19443)
- Backport go-gitea#19443 - Add a return for the first "block" of errors, which fixes the double error messages. - Add a return for `externallyManaged`. - Resolves go-gitea#19398
1 parent 6bddfd3 commit 3785221

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

routers/api/v1/user/key.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,21 @@ func DeletePublicKey(ctx *context.APIContext) {
266266
id := ctx.ParamsInt64(":id")
267267
externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(id)
268268
if err != nil {
269-
ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
269+
if asymkey_model.IsErrKeyNotExist(err) {
270+
ctx.NotFound()
271+
} else {
272+
ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
273+
}
274+
return
270275
}
276+
271277
if externallyManaged {
272278
ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
279+
return
273280
}
274281

275282
if err := asymkey_service.DeletePublicKey(ctx.User, id); err != nil {
276-
if asymkey_model.IsErrKeyNotExist(err) {
277-
ctx.NotFound()
278-
} else if asymkey_model.IsErrKeyAccessDenied(err) {
283+
if asymkey_model.IsErrKeyAccessDenied(err) {
279284
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
280285
} else {
281286
ctx.Error(http.StatusInternalServerError, "DeletePublicKey", err)

0 commit comments

Comments
 (0)