refactor: share package registry error status classification (#39133)

Signed-off-by: silverwind <me@silverwind.io>
This commit is contained in:
silverwind
2026-09-03 18:43:30 +00:00
committed by GitHub
parent 0fff5f481e
commit c285440e03
11 changed files with 22 additions and 62 deletions
+10
View File
@@ -4,6 +4,7 @@
package helper
import (
"errors"
"fmt"
"io"
"net/http"
@@ -12,9 +13,18 @@ import (
packages_model "gitea.dev/models/packages"
"gitea.dev/modules/log"
"gitea.dev/modules/setting"
"gitea.dev/modules/util"
"gitea.dev/services/context"
)
// PackageErrorStatus returns the status to report for a package lookup error
func PackageErrorStatus(err error) int {
if errors.Is(err, util.ErrNotExist) {
return http.StatusNotFound
}
return http.StatusInternalServerError
}
// ProcessErrorForUser logs the error and returns a user-error message for the end user.
// If the status is http.StatusInternalServerError, the message is stripped for non-admin users in production.
func ProcessErrorForUser(ctx *context.Context, status int, errObj any) string {