Skip to content

Commit 0663194

Browse files
committed
Fix delete nonexist oauth application 500
1 parent 84f5a0b commit 0663194

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

integrations/api_oauth2_apps_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ func testAPIDeleteOAuth2Application(t *testing.T) {
9292
session.MakeRequest(t, req, http.StatusNoContent)
9393

9494
models.AssertNotExistsBean(t, &models.OAuth2Application{UID: oldApp.UID, Name: oldApp.Name})
95+
96+
// Delete again will return not found
97+
session.MakeRequest(t, req, http.StatusNotFound)
9598
}
9699

97100
func testAPIGetOAuth2Application(t *testing.T) {

models/oauth2_application.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func deleteOAuth2Application(sess *xorm.Session, id, userid int64) error {
235235
if deleted, err := sess.Delete(&OAuth2Application{ID: id, UID: userid}); err != nil {
236236
return err
237237
} else if deleted == 0 {
238-
return fmt.Errorf("cannot find oauth2 application")
238+
return ErrOAuthApplicationNotFound{ID: id}
239239
}
240240
codes := make([]*OAuth2AuthorizationCode, 0)
241241
// delete correlating auth codes

routers/api/v1/user/app.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,11 @@ func DeleteOauth2Application(ctx *context.APIContext) {
274274
// "$ref": "#/responses/empty"
275275
appID := ctx.ParamsInt64(":id")
276276
if err := models.DeleteOAuth2Application(appID, ctx.User.ID); err != nil {
277-
ctx.Error(http.StatusInternalServerError, "DeleteOauth2ApplicationByID", err)
277+
if models.IsErrOAuthApplicationNotFound(err) {
278+
ctx.NotFound()
279+
} else {
280+
ctx.Error(http.StatusInternalServerError, "DeleteOauth2ApplicationByID", err)
281+
}
278282
return
279283
}
280284

0 commit comments

Comments
 (0)