Skip to content

Commit

Permalink
Don't leak real error on search repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Mar 18, 2024
1 parent 69f54db commit 413b6c0
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions routers/web/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,14 @@ func SearchRepo(ctx *context.Context) {
if ctx.FormBool("count_only") {
count, err := repo_model.CountRepository(ctx, opts)
if err != nil {
log.Error("CountRepository: %v", err)
errStr := "CountRepository internal error"
if ctx.Doer != nil && ctx.Doer.IsAdmin {
errStr += ": " + err.Error()
}
ctx.JSON(http.StatusInternalServerError, api.SearchError{
OK: false,
Error: err.Error(),
Error: errStr,
})
return
}
Expand All @@ -638,9 +643,14 @@ func SearchRepo(ctx *context.Context) {

repos, count, err := repo_model.SearchRepository(ctx, opts)
if err != nil {
log.Error("SearchRepository: %v", err)
errStr := "SearchRepository internal error"
if ctx.Doer != nil && ctx.Doer.IsAdmin {
errStr += ": " + err.Error()
}
ctx.JSON(http.StatusInternalServerError, api.SearchError{
OK: false,
Error: err.Error(),
Error: errStr,
})
return
}
Expand All @@ -650,6 +660,14 @@ func SearchRepo(ctx *context.Context) {
latestCommitStatuses, err := commitstatus_service.FindReposLastestCommitStatuses(ctx, repos)
if err != nil {
log.Error("FindReposLastestCommitStatuses: %v", err)
errStr := "FindReposLastestCommitStatuses internal error"
if ctx.Doer != nil && ctx.Doer.IsAdmin {
errStr += ": " + err.Error()
}
ctx.JSON(http.StatusInternalServerError, api.SearchError{
OK: false,
Error: errStr,
})
return
}

Expand Down

0 comments on commit 413b6c0

Please sign in to comment.