2024-05-27 11:32:54 +08:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/repo"
|
|
|
|
)
|
|
|
|
|
|
|
|
func LoadErrCode(errInfo string) int {
|
|
|
|
settingRepo := repo.NewISettingRepo()
|
|
|
|
codeVal, err := settingRepo.Get(settingRepo.WithByKey("NoAuthSetting"))
|
|
|
|
if err != nil {
|
|
|
|
return 500
|
|
|
|
}
|
|
|
|
|
|
|
|
switch codeVal.Value {
|
|
|
|
case "400":
|
|
|
|
return http.StatusBadRequest
|
|
|
|
case "401":
|
|
|
|
return http.StatusUnauthorized
|
|
|
|
case "403":
|
|
|
|
return http.StatusForbidden
|
|
|
|
case "404":
|
2024-06-04 22:29:05 +08:00
|
|
|
return http.StatusNotFound
|
2024-05-27 11:32:54 +08:00
|
|
|
case "408":
|
|
|
|
return http.StatusRequestTimeout
|
|
|
|
case "416":
|
|
|
|
return http.StatusRequestedRangeNotSatisfiable
|
|
|
|
default:
|
|
|
|
return http.StatusOK
|
|
|
|
}
|
|
|
|
}
|