File tree Expand file tree Collapse file tree 3 files changed +10
-16
lines changed Expand file tree Collapse file tree 3 files changed +10
-16
lines changed Original file line number Diff line number Diff line change @@ -506,10 +506,7 @@ func deletePublicKeys(e *xorm.Session, keyIDs ...int64) error {
506
506
func DeletePublicKey (doer * User , id int64 ) (err error ) {
507
507
key , err := GetPublicKeyByID (id )
508
508
if err != nil {
509
- if IsErrKeyNotExist (err ) {
510
- return nil
511
- }
512
- return fmt .Errorf ("GetPublicKeyByID: %v" , err )
509
+ return err
513
510
}
514
511
515
512
// Check if user has access to delete this key.
Original file line number Diff line number Diff line change @@ -258,26 +258,19 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
258
258
// responses:
259
259
// "204":
260
260
// "$ref": "#/responses/empty"
261
- // "404":
262
- // "$ref": "#/responses/notFound"
263
261
// "403":
264
262
// "$ref": "#/responses/forbidden"
263
+ // "404":
264
+ // "$ref": "#/responses/notFound"
265
265
u := user .GetUserByParams (ctx )
266
266
if ctx .Written () {
267
267
return
268
268
}
269
269
270
- if _ , err := models .GetPublicKeyByID ( ctx .ParamsInt64 (":id" )); err != nil {
270
+ if err := models .DeletePublicKey ( u , ctx .ParamsInt64 (":id" )); err != nil {
271
271
if models .IsErrKeyNotExist (err ) {
272
272
ctx .Status (404 )
273
- } else {
274
- ctx .Error (500 , "DeleteUserPublicKey" , err )
275
- }
276
- return
277
- }
278
-
279
- if err := models .DeletePublicKey (u , ctx .ParamsInt64 (":id" )); err != nil {
280
- if models .IsErrKeyAccessDenied (err ) {
273
+ } else if models .IsErrKeyAccessDenied (err ) {
281
274
ctx .Error (403 , "" , "You do not have access to this key" )
282
275
} else {
283
276
ctx .Error (500 , "DeleteUserPublicKey" , err )
Original file line number Diff line number Diff line change @@ -178,8 +178,12 @@ func DeletePublicKey(ctx *context.APIContext) {
178
178
// "$ref": "#/responses/empty"
179
179
// "403":
180
180
// "$ref": "#/responses/forbidden"
181
+ // "404":
182
+ // "$ref": "#/responses/notFound"
181
183
if err := models .DeletePublicKey (ctx .User , ctx .ParamsInt64 (":id" )); err != nil {
182
- if models .IsErrKeyAccessDenied (err ) {
184
+ if models .IsErrKeyNotExist (err ) {
185
+ ctx .Status (404 )
186
+ } else if models .IsErrKeyAccessDenied (err ) {
183
187
ctx .Error (403 , "" , "You do not have access to this key" )
184
188
} else {
185
189
ctx .Error (500 , "DeletePublicKey" , err )
You can’t perform that action at this time.
0 commit comments