mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-08 14:03:24 +09:00
refactor: share package registry error status classification (#39133)
Signed-off-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user