Skip to content

Commit 413b6c0

Browse files
committed
Don't leak real error on search repositories
1 parent 69f54db commit 413b6c0

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

routers/web/repo/repo.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,14 @@ func SearchRepo(ctx *context.Context) {
626626
if ctx.FormBool("count_only") {
627627
count, err := repo_model.CountRepository(ctx, opts)
628628
if err != nil {
629+
log.Error("CountRepository: %v", err)
630+
errStr := "CountRepository internal error"
631+
if ctx.Doer != nil && ctx.Doer.IsAdmin {
632+
errStr += ": " + err.Error()
633+
}
629634
ctx.JSON(http.StatusInternalServerError, api.SearchError{
630635
OK: false,
631-
Error: err.Error(),
636+
Error: errStr,
632637
})
633638
return
634639
}
@@ -638,9 +643,14 @@ func SearchRepo(ctx *context.Context) {
638643

639644
repos, count, err := repo_model.SearchRepository(ctx, opts)
640645
if err != nil {
646+
log.Error("SearchRepository: %v", err)
647+
errStr := "SearchRepository internal error"
648+
if ctx.Doer != nil && ctx.Doer.IsAdmin {
649+
errStr += ": " + err.Error()
650+
}
641651
ctx.JSON(http.StatusInternalServerError, api.SearchError{
642652
OK: false,
643-
Error: err.Error(),
653+
Error: errStr,
644654
})
645655
return
646656
}
@@ -650,6 +660,14 @@ func SearchRepo(ctx *context.Context) {
650660
latestCommitStatuses, err := commitstatus_service.FindReposLastestCommitStatuses(ctx, repos)
651661
if err != nil {
652662
log.Error("FindReposLastestCommitStatuses: %v", err)
663+
errStr := "FindReposLastestCommitStatuses internal error"
664+
if ctx.Doer != nil && ctx.Doer.IsAdmin {
665+
errStr += ": " + err.Error()
666+
}
667+
ctx.JSON(http.StatusInternalServerError, api.SearchError{
668+
OK: false,
669+
Error: errStr,
670+
})
653671
return
654672
}
655673

0 commit comments

Comments
 (0)