Skip to content

Commit 8210f6c

Browse files
GustedAbdulrhmnGhanem
Gusted
authored andcommitted
Fix DELETE request for non-existent public key (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 be9d555 commit 8210f6c

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
@@ -262,16 +262,21 @@ func DeletePublicKey(ctx *context.APIContext) {
262262
id := ctx.ParamsInt64(":id")
263263
externallyManaged, err := asymkey_model.PublicKeyIsExternallyManaged(id)
264264
if err != nil {
265-
ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
265+
if asymkey_model.IsErrKeyNotExist(err) {
266+
ctx.NotFound()
267+
} else {
268+
ctx.Error(http.StatusInternalServerError, "PublicKeyIsExternallyManaged", err)
269+
}
270+
return
266271
}
272+
267273
if externallyManaged {
268274
ctx.Error(http.StatusForbidden, "", "SSH Key is externally managed for this user")
275+
return
269276
}
270277

271278
if err := asymkey_service.DeletePublicKey(ctx.Doer, id); err != nil {
272-
if asymkey_model.IsErrKeyNotExist(err) {
273-
ctx.NotFound()
274-
} else if asymkey_model.IsErrKeyAccessDenied(err) {
279+
if asymkey_model.IsErrKeyAccessDenied(err) {
275280
ctx.Error(http.StatusForbidden, "", "You do not have access to this key")
276281
} else {
277282
ctx.Error(http.StatusInternalServerError, "DeletePublicKey", err)

0 commit comments

Comments
 (0)