diff --git a/backend/app/api/v1/auth.go b/backend/app/api/v1/auth.go index be2727060..e1959e1dc 100644 --- a/backend/app/api/v1/auth.go +++ b/backend/app/api/v1/auth.go @@ -124,7 +124,11 @@ func (b *BaseApi) CheckIsSafety(c *gin.Context) { return } if status == "unpass" { - helper.ErrResponse(c, middleware.LoadErrCode("err-entrance")) + if middleware.LoadErrCode("err-entrance") != 200 { + helper.ErrResponse(c, middleware.LoadErrCode("err-entrance")) + return + } + helper.ErrorWithDetail(c, constant.CodeErrEntrance, constant.ErrTypeInternalServer, nil) return } helper.SuccessWithOutData(c) diff --git a/backend/middleware/bind_domain.go b/backend/middleware/bind_domain.go index 2bc97f119..1b561cbe6 100644 --- a/backend/middleware/bind_domain.go +++ b/backend/middleware/bind_domain.go @@ -1,6 +1,7 @@ package middleware import ( + "errors" "strings" "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" @@ -28,7 +29,11 @@ func BindDomain() gin.HandlerFunc { } if domains != status.Value { - helper.ErrResponse(c, LoadErrCode("err-domain")) + if LoadErrCode("err-domain") != 200 { + helper.ErrResponse(c, LoadErrCode("err-domain")) + return + } + helper.ErrorWithDetail(c, constant.CodeErrDomain, constant.ErrTypeInternalServer, errors.New("domain not allowed")) return } c.Next() diff --git a/backend/middleware/helper.go b/backend/middleware/helper.go index 1f5a453ef..b25c99907 100644 --- a/backend/middleware/helper.go +++ b/backend/middleware/helper.go @@ -4,7 +4,6 @@ import ( "net/http" "github.com/1Panel-dev/1Panel/backend/app/repo" - "github.com/1Panel-dev/1Panel/backend/constant" ) func LoadErrCode(errInfo string) int { @@ -22,21 +21,12 @@ func LoadErrCode(errInfo string) int { case "403": return http.StatusForbidden case "404": - return http.StatusFound + return http.StatusNotFound case "408": return http.StatusRequestTimeout case "416": return http.StatusRequestedRangeNotSatisfiable default: - if errInfo == "err-ip" { - return constant.CodeErrIP - } - if errInfo == "err-domain" { - return constant.CodeErrDomain - } - if errInfo == "err-entrance" { - return constant.CodeErrEntrance - } return http.StatusOK } } diff --git a/backend/middleware/ip_limit.go b/backend/middleware/ip_limit.go index 8f2e3536b..9bef2b80a 100644 --- a/backend/middleware/ip_limit.go +++ b/backend/middleware/ip_limit.go @@ -1,6 +1,7 @@ package middleware import ( + "errors" "net" "strings" @@ -34,7 +35,11 @@ func WhiteAllow() gin.HandlerFunc { return } } - helper.ErrResponse(c, LoadErrCode("err-ip")) + if LoadErrCode("err-ip") != 200 { + helper.ErrResponse(c, LoadErrCode("err-ip")) + return + } + helper.ErrorWithDetail(c, constant.CodeErrIP, constant.ErrTypeInternalServer, errors.New("IP address not allowed")) } } diff --git a/backend/middleware/password_expired.go b/backend/middleware/password_expired.go index 389558b44..9b77208e1 100644 --- a/backend/middleware/password_expired.go +++ b/backend/middleware/password_expired.go @@ -33,11 +33,11 @@ func PasswordExpired() gin.HandlerFunc { loc, _ := time.LoadLocation(common.LoadTimeZone()) expiredTime, err := time.ParseInLocation("2006-01-02 15:04:05", extime.Value, loc) if err != nil { - helper.ErrResponse(c, constant.CodePasswordExpired) + helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err) return } if time.Now().After(expiredTime) { - helper.ErrResponse(c, constant.CodePasswordExpired) + helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err) return } c.Next() diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index f7487bc05..4f89cb9b8 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -55,6 +55,22 @@ class RequestHttp { globalStore.errStatus = 'err-found'; return; } + if (data.code == ResultEnum.ERRIP) { + globalStore.errStatus = 'err-ip'; + return; + } + if (data.code == ResultEnum.ERRDOMAIN) { + globalStore.errStatus = 'err-domain'; + return; + } + if (data.code == ResultEnum.UNSAFETY) { + globalStore.errStatus = 'err-unsafe'; + return; + } + if (data.code == ResultEnum.EXPIRED) { + globalStore.errStatus = 'err-entrance'; + return; + } if (data.code == ResultEnum.ERRXPACK) { globalStore.isProductPro = false; window.location.reload(); @@ -109,7 +125,6 @@ class RequestHttp { router.push({ name: 'Expired' }); return; case 500: - case 400: case 407: checkStatus( response.status, @@ -122,6 +137,7 @@ class RequestHttp { name: 'entrance', params: { code: globalStore.entrance }, }); + return; } } if (!window.navigator.onLine) router.replace({ path: '/500' }); diff --git a/frontend/src/components/error-message/error_code.vue b/frontend/src/components/error-message/error_code.vue index d5c1ea226..00a93614f 100644 --- a/frontend/src/components/error-message/error_code.vue +++ b/frontend/src/components/error-message/error_code.vue @@ -19,17 +19,20 @@ const props = defineProps({ code: String, }); const loadErrInfo = () => { + console.log(props.code); switch (props.code) { + case '400': + return '400 Bad Request'; case '401': return '401 Unauthorized'; case '403': return '403 Forbidden'; case '404': - return '403 Not Found'; + return '404 Not Found'; case '408': return '408 Request Timeout'; case '416': - return '408 Requested Not Satisfiable'; + return '416 Requested Not Satisfiable'; } }; diff --git a/frontend/src/views/login/entrance/index.vue b/frontend/src/views/login/entrance/index.vue index 59d76fafb..12ec52019 100644 --- a/frontend/src/views/login/entrance/index.vue +++ b/frontend/src/views/login/entrance/index.vue @@ -83,21 +83,8 @@ const getStatus = async () => { loading.value = false; loadDataFromXDB(); }) - .catch((err) => { + .catch(() => { loading.value = false; - switch (err.response.status) { - case 310: - errStatus.value = 'err-ip'; - return; - case 311: - errStatus.value = 'err-domain'; - return; - case 312: - errStatus.value = 'err-entrance'; - return; - default: - errStatus.value = 'code-' + err.response.status; - } }); };